I have created a list view and i have added some item, can anybody help me to get the item text in on Item Click listener?
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView <? > parent, View view,
int position, long id) {
Object o = parent.getItemAtPosition(position);
String keyword = o.toString();
Log.v("value ", "result is " + keyword);
}
});
I have tried the above code but it does not work...
Try this: my_listview. setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { } });
OnItemClickListener MshowforItem = new AdapterView. OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((TextView)view). setText("Hello"); } };
android.widget.AdapterView.OnItemClickListener. Known indirect subclasses. CharacterPickerDialog, PreferenceScreen. CharacterPickerDialog. Dialog for choosing accented characters related to a base character.
I assume you have TextView
on the item.
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView <? > parent, View view,
int position, long id) {
TextView txt = (TextView) parent.getChildAt(position - lv.firstVisiblePosition()).findViewById(R.id.mylistviewtextview);
String keyword = txt.getText().toString();
Log.v("value ", "result is " + keyword);
}
});
or you can retrieve the text from the ArrayList
you feed the ListView
First of all, the correct event to intercept for selection is onItemSelected
because a selection might not have been made in the onClick handler. And then the question has been well treated here on stackoverflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With