android – How to display in the ListView a single data from a query that returns two data?

Question:

I have a query that returns a person's first and last name. With the result of this query , I insert the information into a ListView and the first and last name are displayed.

How do I display only the name?

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

Note: Unfortunately I can't change the query , it must return the first and last name, I can't use CursorAdapter in the query either .

Answer:

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

Example to solve your problem:

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