I am trying to make a dialog that basically asks for the genre of the song from the user. Thus I have two buttons and an EditText. I want to fetch the string from EditText when I hit the "Save" button and save it to the database. but the problem is the EditText is returning and empty string which can be due to the fact that I just can't relate the Edittext to the one in the layout. Code Snippet:
class AskGenreDialog {
private String songTitle = "";
private int id;
EditText AskGenre;
View view;
public void setSongTitle(String songTitle){
this.songTitle = songTitle;
}
public void setId(int id){
this.id = id;
}
public void onCreateDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(MusicPlayerActivity.this);
LayoutInflater inflator = (LayoutInflater)MusicPlayerActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
builder.setView(inflator.inflate(R.layout.ask_genre, null));
builder.setTitle("Genre Not Found").setMessage(songTitle);
view = inflator.inflate(R.layout.ask_genre, null);
AskGenre = (EditText) view.findViewById(R.id.genre);
builder.setPositiveButton("Save", new OnClickListener(){
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
String genre =AskGenre.getText().toString();
handler.setGenreForId(genre,id);
Log.d("Ans:", genre);
}
});
builder.setNegativeButton("Don't Know", new OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
// create alert dialog
AlertDialog alertDialog = builder.create();
// show it
alertDialog.show();
}
}
Can anyone tell me the problem please?