Saturday, 31 August 2013

Get the number/position of a button in a ListView

Get the number/position of a button in a ListView

I put a button on a each row of a ListView and now I want to get the
position (number of the row) of that button and show it using TOAST when
some one press that button, not the row.
I don't know how to do that, I can't even show the Toast, here is my code:
ListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> list, View view, int
position, long id) {
Log.i(TAG, "onListItemClick: " + position);
Toast.makeText(MainActivity.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
I'm learnign how to develope for android and I'm not an english native
speaker, Thanks for your help!

No comments:

Post a Comment