【发布时间】:2015-05-23 18:07:41
【问题描述】:
我有一个ListView,当单击一个项目时,它会创建新的 PlaySongAlertDialog 对象并将参数传递给它。现在下面代码的问题是,只有在第一次它实际上改变了artistCheckBox 的文本,当我点击关闭然后在另一个ListView 行上它显示artistCheckBox 上的相同文本。
我找不到帖子,但我记得有人说我应该覆盖onPrepareDialog,但我在AlertDialog.Builder 类上找不到这种方法。
public class PlaySongAlertDialog extends AlertDialog.Builder {
public PlaySongAlertDialog(final Context context, final String songName, final Intent service) {
super(context);
LayoutInflater inflater = LayoutInflater.from(context);
View dialoglayout = inflater.inflate(R.layout.download_song_alert_dialog_check_box, null);
final CheckBox artistCheckBox = (CheckBox) dialoglayout.findViewById(R.id.artist_checkbox);
final CheckBox albumCheckBox = (CheckBox) dialoglayout.findViewById(R.id.album_checkbox);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try{
artistCheckBox.setText("Add artist name (" + getSomethingFromTheWeb.getArtist(songName) +")");
} catch(Exception e){
artistCheckBox.setText("Add artist name (can't found)" );
artistCheckBox.setClickable(false);
}
}
});
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
setMessage("Do you want to play: " + songName);
setView(dialoglayout);
}
这也是我创建新对话框的方式(此代码在主要活动中)
DownloadSongAlertDialog dialog = new DownloadSongAlertDialog(this, name, serviceIntent);
dialog.show();
有没有办法每次都创建一个真实的对话框,而不是重复使用最后一个对话框,也许清理缓存之类的。
【问题讨论】:
标签: android android-alertdialog layout-inflater