Android - setOnClickListener for TextView

后端 未结 6 2047
孤街浪徒
孤街浪徒 2021-02-05 10:47

It should be straightforward, but I am not sure where something is wrong. I try to catch the click on the TextView with:

public void runNextTask(){
         


        
6条回答
  •  我寻月下人不归
    2021-02-05 11:20

    You can remove this:

    android:onClick="onClick"
    

    Or, remove this:

    modelTextview.setOnClickListener(new OnClickListener() {
        @Override
         public void onClick(View v) {
    
         }
    });
    

    and have this:

    public void onClick(View v)
    {
        // do something
    }  
    

    android:onClick="onClick"/> // It would be better to rename the method to avoid confusion

    Also, you have this:

    so initialize your TextView as below:

    TextView modelTextview = (TextView)addView.findViewById(R.id.model);
    

提交回复
热议问题