如何在“自定义”对话框中获取Card View的ID

时间:2018-07-04 16:42:59

标签: android dialog

我已经创建了一个自定义对话框,并希望在其中获取卡片视图的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;

        }
    }
}

1 个答案:

答案 0 :(得分:0)

添加点击监听器以查看

Per25cardView=findViewById(R.id.per25);
Per25cardView.setOnClickListner(this);