Hello everyone
My current problem is how to extract a text from a custom listview. Instead of extracting the text it extracts a numeric value but in String, an example the text is chocolate and instead of extracting chocolate it extracts 0 or it can be greater. My point of view is that instead of extracting the text it extracts the position. I don't know if I'm right?
And because I mean custom custom: for the reason that my code returned me the correct value either in a listview with an ordinary adapter not a custom one and when implementing the custom one to display images it gives 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 delighted to hear your ideas. Thank you
In your code you don't show a
listView
, you show agridview
.If you want to get the text of an item in a
ListView
, it's done like this:How to extract the text of a
listView
personalized?If you want to get it from a
ListView
custom, you must refer to a custom layout for the elements in theListView
, I add an example in the event that the text is in a TextView of this layout assuming an id calledmyText
:To get the text of a
TextView
you must use the methodgetText()
String listChoice = (gridview.getItemAtPosition (position)).getText().toString();
Maybe you should cast a
TextView
:String listChoice = ((TextView) gridview.getItemAtPosition (position))).getText().toString();