D
D
den_kvlchk2021-03-11 13:46:29
Java
den_kvlchk, 2021-03-11 13:46:29

How to list multiple columns from a database in one row of a ListView?

Good day to all! I have a database in which there are a lot of different columns, for example, there is a list of cats:
Name Age Gender Favorite toy City of residence, etc.
Vasya, 2 years old, ball Moscow ....
Actually, the essence of the problem, for example, we have a lot of cats and I need to flip through them, that is, use the ListView method, how to make each cat appear like this:
Vasya, 2 years old, m, ball, Moscow, . ..,...,...
Musya, 3 years old, f, wand, Moscow,..,...,...,
if there is a chance to do better, then it would be more ideal:
name: Vasya, age: 2 years old, gender: m, toy: ball, city: Moscow, ...,...,...
name: Musya, age: 3 years old, gender: f, toy: stick, city: Moscow,..,...,...,
I have the following code
String[] headers = new String[]{DatabaseHelper.COLUMN_NAME , DatabaseHelper.COLUMN_YEAR, DatabaseHelper.COLUMN_CITY, DatabaseHelper.COLUMN_STREET, DatabaseHelper.COLUMN_HOME,
DatabaseHelper.COLUMN_FILM, DatabaseHelper.COLUMN_GAME};
// create adapter, pass cursor to it
userAdapter = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item,
userCursor, headers, new int[]{android.R.id.text1, android.R.id.text2}, 0);
userList.setAdapter(userAdapter);
I understand that I need to somehow change the Simple CursorAdapter, but I don’t understand how to fix it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan, 2021-03-12
@steff

Use RecyclerView and in the onBindViewHolder method collect the necessary values ​​in a string (for example, for TextView)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question