Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

android - ListView and Buttons inside ListView

I want to display a Button inside the ListView. The goal should be to click on the ListView line or on the button.

Click on the line it shows more info. Click on the button it shows at the bottom more buttons.

The same as the GMAIL app.

On the right there is a checkbox and after clicking on the checkbox at the bottom, the button bar appears.

My problem is after inserting the button into the ListView, the button is not clickable. If I add the to the LinearLayout from the button llButton.setClickable() it works. But, only the button. The ListView itself doesn't react on clicks anymore!

I have tried this example.

The same issue as above...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just to make this clear – and no one seems to have said something this simple – whilst one is not allowed to have a focusable button work in conjunction with the list view, there is a much simpler solution for this.

The accepted answer is a given - you should always do that when setting the click listener for list items, so that is silly that OP didn't know that.

If you are using an XML layout as your list item, simply set the button to have the following attribute and it will cause the list item to be clickable as well:

android:focusable="false"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...