我正在尝试制作一个对话框,基本上要求用户提供歌曲的流派。因此,我有两个按钮和一个 EditText。当我点击“保存”按钮并将其保存到数据库时,我想从 EditText 获取字符串。但问题是 EditText 正在返回和空字符串,这可能是因为我无法将 Edittext 与布局中的那个相关联。代码片段:
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();
}
}
谁能告诉我这个问题吗?