How to display in Listview a single query data that returns two data?

Asked

Viewed 97 times

3

I have a query that returns a person’s name and surname. With the result of this query, I enter the information within a ListView and displays the name and surname.

How do I display only the name?

And then I would have to use the string name using the arraAdapter.getItem(position); but also take only the name, could not come the surname.

Note: Unfortunately I cannot change the query, it must return the name and the same surname, also can not use CursorAdapter in query.

  • 2

    Post the code so the answers can be concise.

  • A question. "Name" and "Last name" are separate columns of the table or you save the full name of the person in a "Full Name" column"?

  • Name and Surname are separate columns.

  • Without seeing the code and given the limitations you described, you can use the method split() string and pick up the substring at position 0. Hence do not know if skipping the second name of people with compound name is a problem for your case

1 answer

1

You can separate the name by the spaces using .split();, it will separate your string into an array according to the separator field you enter as parameter.

Example to solve your problem:

String nomeCompleto= "JOÃO DA SILVA";  
String array[] = nomeCompleto.split(" "); 
String primeiroNome = array[0];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.