Adding OnClick(View v) in a textview

后端 未结 4 405
鱼传尺愫
鱼传尺愫 2021-01-28 08:55

i have added onClick in my mainactivity for my textview and i had no errors but when i run the app it crashes saying app has stopped working even though i have no errors in my c

4条回答
  •  深忆病人
    2021-01-28 09:25

    Change to

    public void runNextTask(View v){ // method signature is worng
    

    Also if textView is in activity_main.xml. There is no need to inflate the layout

    setContentView(R.layout.activity_main); // is enough
    

    And initialize textView in onCreate

    TextView modelTextview = (TextView)findViewById(R.id.state2); 
    

    If you want to have click listener progrmatically remove

    android:onClick="runNextTask"
    

提交回复
热议问题