Android: Get the listview item from button clicked in custom listview

后端 未结 5 584
终归单人心
终归单人心 2021-02-02 16:17

I have a custom ListView with two button and I when I click either button on any row I want to get the text label on the Listview and for now just popup a toast with it. So far

5条回答
  •  醉梦人生
    2021-02-02 16:49

    Set onClick="click" to xml of button/image/etc...

    and in your Activity, do:

    public void click(View v) {
        final int position = getListView().getPositionForView(v);
        String text = getListView().getItemAtPosition(position).toString();
        Toast.makeText(getApplicationContext, text, Toast.LENGTH_SHORT).show();
    }
    

提交回复
热议问题