Home > Software design >  How I can create history layout in android studio such as recent
How I can create history layout in android studio such as recent

Time:05-27

I am building an app include edit text and button. The user can put text in the edit text, then click button to transfer him to the browser. So, I would like to create other layout as recent to store the text that the user entered on the edit text.

How I can do that? I need the logic or code that can help me! Also, should I have create database to store the data?

Example: enter image description here

CodePudding user response:

You can store data in multiple ways, and you will need to understand what is right for your use case. You can store data in memory, by simply creating a List with your data type and adding to it every time user will click a button, but then it will not persist between sessions with the app.

If you want the data to persist, then you would need to use permanent storage, and there are a lot of options here:

  • You could use Shared Preferences

  • You could use File System and save the data to a file

  • You could use a database i.e SQLite, and store data there

  • You could use external server, and get the data through REST API.

Generally, there is a good overview of data storage in Android in the documentation which also have code examples.

Every option comes in multiple ways to accomplish it. There are built-in solutions, and multiple libraries to help you with this task, but first of all, you will need to understand what is the predicted usage of this data. I.E Should user have access to the data from another device? Should the data be available offline? Will data have complex structure? How the app can expand in the future? e.t.c.

Only by knowing this you can design how you will handle it.

If you need logic or code to create view, then you will need ListView, or RecyclerView, Adapter for handling the data, extra xml layout file for single item of your data.

  • Related