-1

膨らんだレイアウトでアラートダイアログを開くサーフェスビューがあります。このレイアウトの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

dialogLayout作業しているダイアログのレイアウトであるため、代わりにImageView を見つける必要があります。

更新されたコードは次のようになります。

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