문제

I have a customized list item with 2 Buttons ( save , share) in a ListView.

How to get which Button is clicked in list item in onItemClick() method ?

Like:

      ListView
----------------------------
[Text]
[SAVE BUTTON1][SHARE BUTTON2]
-----------------------------
[Text]
[SAVE BUTTON1][SHARE BUTTON2]
-----------------------------
[Text]
[SAVE BUTTON1][SHARE BUTTON2]
-----------------------------
-
-
도움이 되었습니까?

해결책

You can do the following,

set Tag to your Button in the getView() method of your ListView

btn.setTag(position);

then set OnClickListener to your button,

btn.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        Toast.makeText(getApplicationContext(), "button position is: "+v.getTag(),
   Toast.LENGTH_LONG).show();
    }
});

다른 팁

For custom adapters you should use View.OnClickListener and set it to each individual element Button using setOnClickListener() method.

the onItemClick() is part of OnItemClickListener that only responds to click on the whole view. This is usually used for simpler lists using one of the default adapters.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top