dimanche 22 février 2015

[Q] rpoblems with the on click listner :( topic






hi guys im trying to set an app to have a send sms function to non changing phone number for " opening a service call" thingy for users that have warranty on some electric product that they have bought but i got some problem i wish one of you can help heres the info :
this is the XML :
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textsms"
android:layout_marginTop="94dp"
android:hint="fill in the problem and location and cellphone number"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send service request"
android:id="@+id/buttonSms"
android:layout_marginTop="121dp"
android:layout_below="@+id/textsms"
android:layout_centerHorizontal="true"
android:onClick="smsClick"/>

this is the java:

//smssending

Button buttonSms;
EditText textsms;


buttonSms = (Button) findViewById(R.id.buttonSms);
textsms = (EditText) findViewById(R.id.textsms);
final String editPhoneNum = "052444444";
buttonSms.setOnClickListener (new OnClickListener()

{



public void smsClick(View v) {

String phoneNo = editPhoneNum;
String sms = textsms.getText().toString();

try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent!",
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS faild, please try again later!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}


}
);








Attached Thumbnails


Click image for larger version<br/><br/>Name:	problem2.png<br/>Views:	N/A<br/>Size:	54.1 KB<br/>ID:	3178320
 

Click image for larger version<br/><br/>Name:	problem1.png<br/>Views:	N/A<br/>Size:	76.1 KB<br/>ID:	3178321
 

















Aucun commentaire:

Enregistrer un commentaire