I imported a text file into a ListView in android.
If I click an item in listView, it's line number should be stored in an int.
For example (this is a ListView (text file)):
Corn (1)
Apple (2)
Melon (3)
If a line is clicked for example Melon, it's line number (3) should be stored in an int.
The code:
// returns index to -1
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
boolean co = true;
int lineNumber = list.getSelectedItemPosition();
Toast.makeText(MainActivity.this, String.valueOf(lineNumber), Toast.LENGTH_SHORT).show();
}
});
Is that possible?