Within a ListView, why do I keep getting the value of the first row instead of the selected row?

后端 未结 2 1215
醉酒成梦
醉酒成梦 2021-01-27 12:29

In my android app I have the following code:

public void goToCaptureBonus (View View) {
        String tappedBonus = ((TextView) findViewById(R.id.bonusListCode)         


        
2条回答
  •  無奈伤痛
    2021-01-27 13:16

    The documentation of findViewById() says

    Finds the first descendant view with the given ID, ...

    Is it possible that you are using findViewById() from the context of the activity or the the general list view and not of the selected (tapped on) view?

    If the view parameter of your function is the tapped on view, you should probably do:

    view.findViewById(R.id.bonusListCode)
    

    instead of just

    findViewById(R.id.bonusListCode)
    

提交回复
热议问题