The list of recent items in the shopping cart contains the message function, which needs to get the content of the EditText input, which is a bit tricky when buying multiple items.
After checking the data to solve the function, and wrote a case;
:
You can use a field in the product data to manage the message data, so that you can easily operate.
Code:
Public classMainactivityextendsappcompatactivity {listview listview; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initview (); } Private voidInitview () {ListView=(ListView) Findviewbyid (R.id.listview); Listview.setadapter (NewListAdapter ( This)); } Public voidSaveeditdata (intposition, String str) {Toast.maketext ( This, str+ "----" +Position,toast.length_long). Show (); }}
Adapter
Public classListAdapterextendsBaseadapter {context context; Layoutinflater Inflater; String[] Strings=Newstring[]{"Product 1", "Item 2", "Item 3"}; PublicListAdapter (Context context) { This. inflater=Layoutinflater.from (context); This. context=context; } @Override Public intGetCount () {return3; } @Override PublicObject GetItem (intposition) { returnStrings[position]; } @Override Public LongGetitemid (intposition) { returnposition; } @Override PublicView GetView (intposition, View Convertview, ViewGroup parent) {Viewholder holder; if(NULL==Convertview) {Convertview= Inflater.inflate (R.layout.item_multiple_confirm,NULL); Holder=NewViewholder (convertview,position); Convertview.settag (holder); }Else{Holder=(Viewholder) Convertview.gettag (); } holder.tv_name.setText (GetItem (position). ToString ()); returnConvertview; } classviewholder{TextView Tv_name; EditText EditText; PublicViewholder (View view,intpisition) {Tv_name=(TextView) View.findviewbyid (r.id.fill_order_name); EditText=(EditText) View.findviewbyid (R.id.fill_order_ltext); Edittext.settag (pisition);//Save Tag ValueEdittext.addtextchangedlistener (NewTextswitcher ( This)); } } classTextswitcherImplementsTextwatcher {PrivateViewholder Mholder; PublicTextswitcher (Viewholder mholder) { This. Mholder =Mholder; } @Override Public voidBeforetextchanged (Charsequence S,intStartintCountintAfter ) {} @Override Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) { intPosition = (int) MHolder.editText.getTag ();//Take Tag Value( (mainactivity) context). Saveeditdata (position, s.tostring ()); } @Override Public voidaftertextchanged (Editable s) {} }}
code is written relatively simple , source click Download
Get EditText input value from Android-------ListView List