开发者

Combining ListView with button. Need two listeners

I'm trying to combine a listView with a button at the bottom, and everything is working UI-wise, I see my list and the Button at the bottom, except I can't make the app react when the button is clicked.

I need both 开发者_如何学编程the list view and the button to be clickable but I can't extend both ListActivity and Activity.

So, how do I get both a clickable list and a clickable item?


You can create your own OnClickListener within the class as follows:

Set button to use the OnClickListener as such:

 button = (Button)findViewById(R.id.theButton);
 button.setOnClickListener(buttonClickListener);

And create the OnClickListener:

private OnClickListener buttonClickListener = new OnClickListener() {
        public void onClick(View v) {
             // do something
            }
        }
    };

You can then fire off whatever you need within that OnClickListener, while keeping the List clickable as before.


I would imagine that you could just set up a listener for the list items. Then, when an onLIstItemClick event is popped, you would just look at which list item is selected. If it is the list item you know to be a button, cast the item (or item's value) to a button and manually call the button's onClick event.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜