开发者

listview with kopokami in each row, how to handle a click on them?

There is a list of listview, in each row is a button that, when clicked on it to display in this row has one button (delete). I'm still new to android. Tell m开发者_运维百科e how to organize such a behavior, not quite sure how to determine when you click on the button to which line they belong.


You said that you have a delete button in every list row in the listview. I assume that you have a custom layout for the row then. If you have implemented this custom layout in a custom list adapter you have the getView() method in the adapter where you inflate the layout into the row. There you can edit the id of the button like this:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.row, null);
            }
            Button b = (Button) convertView.findViewById(R.id.button);
            // here the id
            b.setId(position);
            return v;
    }

When you get the onclick somewhere in your app you can access the source of the event and get the id.

I don't know if this is a good way to implement it and if it meets your needs but it is a simple solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜