Reputation: 1148
I am working on a simple app in which a bar tender can do the beer pay off automatically. The articles (beer, wine, whisky etc) are listed in a database and I use a SimpleCursorAdapter to map all the articles from the database to a ListView. Works perfectly.
So now it displays a list of articles, prices and a textfield where the bartender can input the quantity of the order (ex 10 beer). Problem: I don't know how I can get those quantities back from the ListView. Does anyone know how to do this?
Thanks in advance
Upvotes: 0
Views: 124
Reputation: 31
If you want to use the OnItemClickListener of your ListView, you can use the View view Parameter to access Sub-Items of the List View Item. You could replace the TextView in the following example with your EditText. Replace android.R.id.text1 with your R.id.x.
yourListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
TextView testAccess = (TextView)(view.findViewById(android.R.id.text1));
Toast.makeText(getApplicationContext(), testAccess.getText()
, Toast.LENGTH_LONG).show();
//do something
}
});
Upvotes: 2
Reputation: 46856
One potential way to do it is to set a button click listener inside of your Adapter getView() method, upon click that button can pull the value out of the EditText. Since you are inside the getView() method you should still have a reference to the EditText that you need.
Upvotes: 0