Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对话框上的视图不';不要在应该改变的时候改变_Android_Android Alertdialog_Layout Inflater - Fatal编程技术网

Android 对话框上的视图不';不要在应该改变的时候改变

Android 对话框上的视图不';不要在应该改变的时候改变,android,android-alertdialog,layout-inflater,Android,Android Alertdialog,Layout Inflater,我有一个列表视图,当单击一个项目时,它会创建一个新的PlaySongAlertDialog对象并将参数传递给它。下面代码的问题是,只有在第一次它实际上更改了artistCheckBox的文本,当我单击discover,然后在另一个ListView行上,它在artistCheckBox上显示相同的文本。 我找不到帖子,但我记得有人说我应该重写onPrepareDialog,但我在AlertDialog.Builder类上找不到这样的方法 public class PlaySongAlertDial

我有一个
列表视图
,当单击一个项目时,它会创建一个新的PlaySongAlertDialog对象并将参数传递给它。下面代码的问题是,只有在第一次它实际上更改了
artistCheckBox
的文本,当我单击discover,然后在另一个
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);
}
这也是我创建新对话框的方式(此代码位于主活动上)

有没有办法每次都创建一个真正的对话框,而不是重复使用最后一个对话框,可以清理缓存或其他东西。

thread.join()正在阻止UI线程,等待其他线程完成。这就是为什么您看不到对话框正在更新的原因。要修复此问题,可以将
AsyncTask
子类化,并在
警报对话框的构造函数中启动它。调用
onPostExecute
时,填写
视图并显示它

DownloadSongAlertDialog dialog = new DownloadSongAlertDialog(this, name, serviceIntent);
dialog.show();