简体   繁体   English

Android-无需大量布局文件即可显示数据的最佳方法

[英]Android - Best way to show data without large amount of layout files

Thanks for all the help recently! 感谢您最近提供的所有帮助! Another question! 另一个问题!

In the app I'm building, I currently have a layout file with an expandable lstview where you can choose 10 options. 在我正在构建的应用程序中,我目前有一个带有可扩展lstview的布局文件,您可以在其中选择10个选项。 When you choose one of those options, you pick another 4 options. 当您选择其中一个选项时,还会选择另外四个选项。 From picking the week, you then have 3 more options. 从选择星期开始,您将有3个更多选择。 Each of those 3 options will currently open a new activity that has a listview with a checkbox and textview in each row, with about 10 rows each. 这3个选项中的每一个当前都将打开一个新活动,该活动的列表视图的每一行都有一个复选框和一个文本视图,每行大约有10行。

Instead of making 30 layout files which will probably crash the app(not sure how many it would take to crash the app), I'm thinking there has to be a better way. 我认为不是制作30个可能会使应用程序崩溃的布局文件(不知道崩溃多少个应用程序),我想必须有一种更好的方法。 I have looked it up and can't really find what I'm looking for. 我查了一下,却找不到我要找的东西。 I have read a little bit about sqlite, but wouldn't you still need separate layout files to call different parts of the tables? 我已经阅读了一些有关sqlite的内容,但是您是否还需要单独的布局文件来调用表的不同部分? Is there a way to make a single layout file with a list view, and fill the listview with different data from sqlite, depending on where the click came from in the expandable list view? 有没有一种方法可以制作一个带有列表视图的布局文件,并用来自sqlite的不同数据填充列表视图,具体取决于单击来自可扩展列表视图的位置?

For example, if they click workout 29 on expandable list view, then click Week 1, then click Day 1.. can that single layout load data from sqlite db. 例如,如果他们在可扩展列表视图上单击“锻炼29”,然后单击“第1周”,然后单击“第1天”。单个布局能否从sqlite db加载数据。 Then if they were to go back and say click workout 30, week 2, day 3, that same layout load different info from the db? 然后,如果他们回去说,单击锻炼30,第2周,第3天,那么相同的布局会加载来自数据库的不同信息吗?

I'm also trying to find out how to make a double expandable list view still 我也在尝试找出如何仍然制作双重可扩展列表视图

Thanks again! 再次感谢!

So this is very simple all you have to do is create a DataAdapter for the listview. 因此,这非常简单,您要做的就是为listview创建一个DataAdapter。 You can then add list view items which bind to the onclick listener and then you can clear that list and add new elements to it. 然后,您可以添加绑定到onclick侦听器的列表视图项,然后可以清除该列表并向其中添加新元素。 a useful link would be. 一个有用的链接是。 https://guides.codepath.com/android/Using-an-ArrayAdapter-with-ListView https://guides.codepath.com/android/Using-an-ArrayAdapter-with-ListView

You should be using a SQLite database for all your data (unless you plan on holding the data in memory which is not a good idea if it is a rather large amount). 您应该对所有数据使用SQLite数据库(除非您计划将数据保存在内存中,否则如果存储量很大,这不是一个好主意)。 You should just create a simple view and keep reusing it. 您应该只创建一个简单的视图并继续重复使用它。 What you will have to do is create your own adapter (extending from BaseExpandableListAdapter for Expandable list views and BaseAdapter for normal list views) and then query the SQLite databse table for the data that you need. 您要做的是创建自己的适配器(从可扩展列表视图的BaseExpandableListAdapter扩展到普通列表视图的BaseAdapter扩展),然后在SQLite数据库表中查询所需的数据。

If you are only displaying String items, you can directly extend ArrayAdapter and then provide the array of items that you want to display for the normal list. 如果仅显示String项,则可以直接扩展ArrayAdapter,然后提供要显示给常规列表的项的数组。

As far as crashing goes, there are many apps that have well over 30 layout files. 就崩溃而言,有许多应用程序具有超过30个布局文件。 Besides even if you did start loading a lot of views, Android will automatically start destroying views as it starts running low on memory and recreate them when it is needed to do so. 此外,即使您确实开始加载大量视图,Android也会在内存不足时自动开始销毁视图,并在需要时重新创建视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM