Answer the question
In order to leave comments, you need to log in
How to determine the selected item of a ListView?
The question is simple, but I can't get it.
The bottom line is that I need to determine the text of the selected ListView element . The ListView
is filled with a parser from an XML file, here is the code:
public class Marsh extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rasp);
ArrayList<String> list = new ArrayList<String>();
try {
XmlPullParser parser = getResources().getXml(R.xml.troll);
while (parser.getEventType()!= XmlPullParser.END_DOCUMENT)
{
if (parser.getEventType() == XmlPullParser.START_TAG && parser.getName().equals("bus"))
{
list.add(parser.getAttributeValue(0));
}
parser.next();
}
}
catch (Throwable t) {
Toast.makeText(this,
"Ошибка при загрузке XML-документа: " + t.toString(), 4000)
.show();
}
setListAdapter(new ArrayAdapter<String>(
this, android.R.layout.simple_list_item_1, list));
OnItemClickListener itemListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
//Что мне тут написать
}
};
getListView().setOnItemClickListener(itemListener);
}
}
Answer the question
In order to leave comments, you need to log in
OnItemClickListener itemListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
String value = getListAdapter().getItem(position);
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question