How to extract the text from a custom listview?


Hello everyone

My current problem is how to extract a text from a custom listview. Instead of extracting the text it extracts a numerical value but in String, an example the text is chocolate and instead of extracting chocolate it extracts 0 or it can be a bigger one. My point of view is that instead of extracting the text, it extracts the position, do not know if I am right?

And because I am referring to personalized custom: for the reason that my code returned the correct value or in a listview with an ordinary adapter not a custom one and when implementing the custom to show images give me this error.

My code

//Aqui almaceno el valor del texto en un String identificándolo por su posición
String listChoice = (gridview.getItemAtPosition (position)).toString();
Toast.makeText(Almacen.this, listChoice, Toast.LENGTH_SHORT).show();

If you know how to solve this problem or have knowledge of another way to achieve my goal. I will be happy to hear your ideas. Thanks

asked by Abraham.P 10.03.2017 в 20:35

2 answers


In your code you do not show a listView , you show a gridview .

If you want to get the text of an item in a ListView , it is done this way:

String textItemList = (listView.getItemAtPosition(position));

How to extract the text from a% custom% co?

If you want to obtain it from a% custom listView , you must refer to a custom layout for the elements in ListView , add an example in case the text is in a TextView of this layout assuming an id called ListView :

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3){
    //Se busca la referencia del TextView en la vista.
    TextView textView = (TextView) arg1.findViewById(;
    //Obtiene el texto dentro del TextView.
    String textItemList  = textView.getText().toString();
answered by 10.03.2017 / 20:54

To get the text of a TextView you must use the getText()


String listChoice = (gridview.getItemAtPosition (position)).getText().toString();

Maybe you should do the cast at TextView :

String listChoice = ((TextView) gridview.getItemAtPosition (position))).getText().toString();

answered by 10.03.2017 в 20:49