ConstraintLayout cannot be cast to android.widget.TextView

后端 未结 2 1105
庸人自扰
庸人自扰 2021-01-27 13:37

I keep getting a runtime error when I try to launch an activity.

Line where the error happen:

private OnItemClickListener mDeviceClickListener = new OnIt         


        
2条回答
  •  臣服心动
    2021-01-27 14:24

    From the documentation:

    View: The view within the AdapterView that was clicked (this will be a view provided by the adapter)

    In your case the View is the root ConstraintLayout. And as the error says you can't cast it to TextView. To get the info you can use:

    String info = v.findViewById(R.id.textView).getText().toString()

提交回复
热议问题