-1

我有一个surfaceview,它打开一个带有膨胀布局的alertdialog,我想在这个布局的imageview上使用一个图像onclicklistener,但是每当我尝试加载对话框时都会得到一个nullpointerexception,当我将onclicklistener设置为imageview时会发生这种情况'鸣叫'。如果我删除侦听器,它将加载而不会出现错误。下面是我的代码

      activity.runOnUiThread(new Runnable(){

                public void run() {
                    AlertDialog.Builder adb = new AlertDialog.Builder(Panel.this.context);

                     try{ 
                         LayoutInflater inflater = ((Activity) context).getLayoutInflater(); 
                        View dialoglayout = inflater.inflate(R.layout.activity_anime_action, null);


                       adb.setView(dialoglayout)
                       .setNegativeButton("Done", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                Intent myIntent = new Intent(context, ActivityOne.class);
                                myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                context.startActivity(myIntent);
                                ((Activity) context).finish(); 
                                dialog.cancel(); 
                            }
                        }); 
                           ImageView tweet = (ImageView)((Activity) context).findViewById(R.id.dialog_tweet);
                           tweet.setOnClickListener(new View.OnClickListener() {

                            public void onClick(View v) {
                                Log.d(VIEW_LOG_TAG, "WORKD");

                            }
                            });
                       }catch(Exception e){Log.d("INFLATER ERROR", e.toString());}
                    adb.show(); 





                }});
4

1 回答 1

0

您应该从中找到 ImageView dialogLayout,因为那是您正在使用的对话框的布局。

更新的代码应该是:

ImageView tweet = (ImageView) dialoglayout.findViewById(R.id.dialog_tweet);
于 2012-12-27T02:26:46.320 回答