开发者

UI help, maybe need to change from a list view?

开发者 https://www.devze.com 2023-02-09 03:22 出处:网络
I want to be able to have a scrollable set of data fetched from a SQLite database (ArrayList) in which when an item is clicked it remains clicked (i.e. the background changes) and some reference to wh

I want to be able to have a scrollable set of data fetched from a SQLite database (ArrayList) in which when an item is clicked it remains clicked (i.e. the background changes) and some reference to which element has been clicked and then if another widget (say a button) is pressed it carries out some action on the highlighted item. See below for an illustration of what I mean. This is a very simplified version.

UI help, maybe need to change from a list view?

So when 'Test Item 1' is selected the background stays yellow and when delete is pressed the item is deleted from the list and the database.

How do I go about this? Are there any tutorials out there开发者_Python百科? Any help is appreciated.


I would can the ListView and make a custom solution. A ScrollView with a vertical LinearLayout in it (to get the scrolling behavior), and you can mimic the selectable item behavior with a ToggleButton. Set the ToggleButtons to be layout_width="fill_parent" and set the background to a custom StateListDrawable. You can add a callback on the ToggleButtons that call a method in the containing activity to update the "selected" item.


Using Rich's solution with dynamic data contains risks. Android's list component contains a lot of automated memory management tricks. Using ScrollView + LinearLayout with large datasets can cause your app to become non-responsive.

Here's a very simple example how you can do really close to what you want to do using only standard list component: http://www.androidpeople.com/android-listview-multiple-choice-example/

Following from there you can move further if you're not satisfied with visuals of that solution.

0

精彩评论

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