J'essaye d'aller chercher la valeur dans src et dest une fois que l'utilisateur clique sur le bouton de navigation mais c'est toujours null. peut aider quelqu'un plzimpossible d'extraire la valeur edittext
static String source = "currentLocation";
static String destination = null;
private void getSrcDest(){
LayoutInflater factory = LayoutInflater.from(this);
final View textEntryView = factory.inflate(R.layout.srcdest, null);
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setIcon(R.drawable.srcdest_icon);
alert.setTitle("Enter Source & Destination");
alert.setView(textEntryView);
final EditText sourceText = (EditText) findViewById(R.id.sourcetext);
final EditText destinationText = (EditText) findViewById(R.id.desttext);
alert.setPositiveButton("Navigate", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try{
Toast.makeText(getApplicationContext(), sourceText.getText().toString()+destinationText.getText().toString(),
Toast.LENGTH_SHORT).show();
source = sourceText.getText().toString();
destination = destinationText.getText().toString();
System.out.println("----------------Source:"+source);
System.out.println("-----------Destination:"+destination);
}
catch(Exception e){
System.out.println("----------------Source:"+source);
System.out.println("-----------Destination:"+destination);
//if(destination.equals(null)){
final AlertDialog.Builder wrongAddressAlert = new AlertDialog.Builder(MainActivity.this);
wrongAddressAlert.setTitle("Destination Address Cannot be Null");
wrongAddressAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
getSrcDest();
}
});
wrongAddressAlert.show();
//}
}
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.cancel();
}
});
alert.show();
}
Je suppose que vous attribuez une valeur de texte à 'source' et' destination' ailleurs dans votre code? –
Oui ... J'ai .. J'ai modifié le code ci-dessus. Jetez un coup d'oeil s'il vous plait. –