Get EditText input value from Android-------ListView List

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.