0
我試圖做一個對話框,基本上要求從用戶的歌曲的流派。 因此,我有兩個按鈕和一個EditText。當我點擊「保存」按鈕並將其保存到數據庫時,我想從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();
}
}
有誰能告訴我這個問題嗎?