Binding an Event to Child of ListView and Changing the ListView based on the Click action in android -


I have a ListView and an Adapter that controls ListView. I want to pair the child to the event click (let's say 'button') ListView. Whenever a button is clicked, I need to apply the changes to the view of the list view.

For example,

Activity:

  Classroom activity activity {ListView listView; Sample Adapter Adapter; & Lt; SampleObject & gt; SampleObjects; OnCreate () {sampleObjects = New ArrayList & lt; SampleObject & gt ;; ListView = findViewById (R.id.listView); Sample Adapter Adapter = New Sample Adapter (Reference, R.Lay Out.list_view_item, Sample Object); ListView.setAdapter (adapter)}}  

Layout of ListViewItem

  & lt; LinearLayout xmlns: android = "http: / /schemas.android.com/apk/res/android" Android: Layout_width = "Match_parent" Android: Layout_height = "Wrap_content" android: orientation = "horizontal" android: padding = "5k0dip "& Gt; & Lt; TextView android: id = "@ + id / sampleName" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_centerVertical = "true" Android: layout_marginLeft = "3.0dip" Android: layout_weight = "1" / & Gt; & Lt; Button android: id = "@ + id / sampleButton" Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" android: text = "@ string / btnText" / & gt; & Lt; / LinearLayout & gt;  

Adapter Class

  Public Class SampleAdapter extends ArrayAdapter & LT; SampleObject & gt; {Public SampleAdapter (Reference Reference, Integer RESOURCEID, Sampling Objects from Objects & Objects) {Super (context, Resource ID, Objects); } @Override View Public getView (final int position, View convertView, ViewGroup parent) {if (convertView == NULL) {LayoutInflater myInflater = (LayoutInflater) getContext () getSystemService (getContext () LAYOUT_INFLATER_SERVICE.). ConvertView = myInflater.inflate (R.layout.friends_list_aitem, null); } Sample object current sample object = getItem (status); TextView name = (text view) Convertview.FindVibeID (RID. Sampling); Name.setText (currentSampleObject.getName ()); Button Button = (Button) ConvertviewFind.ampleButton; Button.setOnClickListener (new OnClickListener () {public void onClick (View view) {// I want to change something in the name of currentSampleObject. And I want to apply the changes to the view of ListItem}}); }}  

In fact, we can get it by a method that Adisucitdetasettag (in) it is said.

The adapter must be the method,

  see the public getView (final integer status, seeviewview, ViewGroup parent) {if (convertView == null) {LayoutInflater myInflater = (LayoutInflater ). GetContext () getSystemService (getContext () LAYOUT_INFLATER_SERVICE.); ConvertView = myInflater.inflate (R.layout.friends_list_aitem, null); } Sample object current sample object = getItem (status); TextView name = (text view) Convertview.FindVibeID (RID. Sampling); Name.setText (currentSampleObject.getName ()); Button Button = (Button) ConvertviewFind.ampleButton; Change the name of Button.setOnClickListener (New OnClickListener () {public void onClick (see view) {// currentSampleObject SampleAdapter.this.notifyDataSetChanged ();}}); }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -