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.
我希望能够从SQLite数据库(ArrayList)中获取一组可滚动的数据,其中单击一个项目时它会保持单击(即背景更改),并且某些元素已被单击,然后是另一个小部件(按下按钮)按下它会对突出显示的项目执行一些操作。请参阅下文,了解我的意思。这是一个非常简化的版本。
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.
因此,当选择“测试项目1”时,背景保持黄色,按下删除时,项目将从列表和数据库中删除。
How do I go about this? Are there any tutorials out there? Any help is appreciated.
我该怎么做?那里有没有教程?任何帮助表示赞赏。
2 个解决方案
#1
0
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.
我可以使用ListView并制作自定义解决方案。其中包含垂直LinearLayout的ScrollView(用于获取滚动行为),您可以使用ToggleButton模仿可选项的行为。将ToggleButtons设置为layout_width =“fill_parent”并将背景设置为自定义StateListDrawable。您可以在调用包含活动中的方法的ToggleButtons上添加回调以更新“已选择”项。
#2
0
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.
使用Rich的动态数据解决方案包含风险。 Android的列表组件包含许多自动化内存管理技巧。将ScrollView + LinearLayout与大型数据集一起使用可能会导致您的应用无响应。
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/
这里有一个非常简单的例子,说明如何使用标准列表组件真正接近您想要做的事情: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.
如果您对该解决方案的视觉效果不满意,那么您可以继续前进。
#1
0
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.
我可以使用ListView并制作自定义解决方案。其中包含垂直LinearLayout的ScrollView(用于获取滚动行为),您可以使用ToggleButton模仿可选项的行为。将ToggleButtons设置为layout_width =“fill_parent”并将背景设置为自定义StateListDrawable。您可以在调用包含活动中的方法的ToggleButtons上添加回调以更新“已选择”项。
#2
0
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.
使用Rich的动态数据解决方案包含风险。 Android的列表组件包含许多自动化内存管理技巧。将ScrollView + LinearLayout与大型数据集一起使用可能会导致您的应用无响应。
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/
这里有一个非常简单的例子,说明如何使用标准列表组件真正接近您想要做的事情: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.
如果您对该解决方案的视觉效果不满意,那么您可以继续前进。