我有一个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();
}});
答案 0 :(得分:0)
您应该从dialogLayout
找到ImageView,因为这是您正在使用的Dialog的布局。
更新的代码应为:
ImageView tweet = (ImageView) dialoglayout.findViewById(R.id.dialog_tweet);