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

后端 未结 5 597
终归单人心
终归单人心 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:57

    Easy to do:

        call.setOnClickListener(new OnClickListener() { 
            @Override 
            public void onClick(View v) { 
                RelativeLayout rl = (RelativeLayout)v.getParent();
                TextView tv = (TextView)rl.findViewById(R.id.label);
                String text = tv.getText().toString();
                Toast.makeText(CustomListView.this, text, Toast.LENGTH_SHORT).show(); 
            } 
        }); 
    

提交回复
热议问题