我已经创建了一个自定义对话框,并希望在其中获取卡片视图的ID。在OnClick方法中,我没有从ID获得任何响应。如何在卡片视图上单击以显示Toast Show?
public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {
CardView Per25cardView;
CardView Per40cardView;
public CustomDialogClass(@NonNull Context context) {
super(context);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.custom_dialog);
Per25cardView=findViewById(R.id.per25);
Per40cardView=findViewById(R.id.per40);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.per25:
Toast.makeText(getContext(), "card view Here we come", Toast.LENGTH_SHORT).show();
break;
}
}
}
答案 0 :(得分:0)
添加点击监听器以查看
Per25cardView=findViewById(R.id.per25);
Per25cardView.setOnClickListner(this);