[英]How to tie up data (title, date etc) to a list of files I'm retrieving from a folder?
I save a list of files into a folder through my app, and when I want to retrieve it, I want to show the Title, date and some other information in each row. 我通过我的应用程序将文件列表保存到文件夹中,当我想要检索它时,我想在每行中显示标题,日期和一些其他信息。 How do I tie up these information with each file?
如何将这些信息与每个文件捆绑在一起?
You can always create an array. 您始终可以创建一个数组。 Let's say you are making an app which receives the contact information stored on your device.
假设您正在制作一个应用程序,它可以接收存储在您设备上的联系信息。 You can do it a bit like this:
你可以这样做:
TextView phoneNumber = (TextView) findViewById(R.id.phone_number);
TextView contactName = (TextView) findViewById(R.id.contact_name);
etc... 等等...
Then, you can set the arrays in your other activity. 然后,您可以在其他活动中设置数组。
String[] contact1;
contact1[0] = "Bob";
contact1[1] = "555-555-5555";
If you are planning to use intents, you have to specify which class you are getting your arrays from. 如果您计划使用意图,则必须指定从哪个类获取数组。 Once you set the arrays and define your TextViews, you can do this:
设置数组并定义TextView后,可以执行以下操作:
contactName.setText("Name: " + contact1[0])
For setting the contacts, you can do this in a loop by setting a number called i and resetting it at the end of each loop. 要设置联系人,可以通过设置一个名为i的数字并在每个循环结束时重置它来循环执行此操作。 This can shorten your lines of code.
这可以缩短您的代码行。 You can do the same with setting the value of the TextViews.
您可以通过设置TextViews的值来执行相同的操作。
If you have further questions, please feel free to reply! 如果您还有其他问题,请随时回复! I will do what I can to help.
我会尽力帮助你。
Regards, 问候,
Ani 阿尼
I suggest storing the date and description for all the list of files in the database. 我建议存储数据库中所有文件列表的日期和描述。
When you are storing the files in the folder at the same time make an entry in the database for a particular file. 当您将文件存储在文件夹中的同时,在数据库中为特定文件创建条目。 Next time you can pick up the details from the database.
下次您可以从数据库中获取详细信息。
Hope this will help you. 希望这会帮助你。
Refer this link to create Sqlite db in android 请参阅此链接以在android中创建Sqlite db
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.