android - Get a reference to same view in multiple inflated layouts -


i tried find answer question, , thought code work wanted but.. it's not.

problem: have "parent" linearlayout add several nested inflated "child" linearlayout's. works. each child layout has 2 views, custom chipview , textview. after inflate each child want able modify chipview , textview of each child "whenever want" during activity.

i created simple project play with, can manage access chipview , textview of first inflated child layout. subsequent ones inserted correctly in parent apparently can't variable reference them.

i doing earlier creating chipview's @ runtime , worked flawlessly, wanted more elegant approach xml can control separately.

in activity have button creates children , 1 should call method in current chipview (i.e. last inflated or 1 click on).

activity:

public class sandboxactivity extends activity {     private button okbtn;     private button add;     private edittext count;     private chipsview chips;     private linearlayout pots;     private textview amount;     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.test);         okbtn = (button) findviewbyid(r.id.ok); //calls method in customviews        add = (button) findviewbyid(r.id.add);  //adds child        count = (edittext) findviewbyid(r.id.count); //the value call methods        pots = (linearlayout) findviewbyid(r.id.pots); //the parent layout         add.setonclicklistener(new button.onclicklistener() {          public void onclick(view v) {             linearlayout ll = (linearlayout) getlayoutinflater().inflate(r.layout.pottemplate, pots);             chips = (chipsview) ll.findviewbyid(r.id.chips);             amount = (textview) ll.findviewbyid(r.id.amount);                 //this should allow me set activity.chips variable last clicked custom view             chips.setonclicklistener(new view.onclicklistener() {                 public void onclick(view v) {                     chips = (chipsview) v;                 }             });                      }          });           okbtn.setonclicklistener(new button.onclicklistener() {              public void onclick(view v) {                 chips.setcount(double.parsedouble(count.gettext().tostring()));                      }          });      } } 

inflated xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >     <com.ded.sandbox.chipsview xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="100dp"         android:layout_height="fill_parent"         android:layout_weight="2"         android:id="@+id/chips">          </com.ded.sandbox.chipsview>      <textview         android:id="@+id/amount"         android:layout_width="100dp"         android:layout_height="wrap_content"         android:text="textview" android:gravity="center_horizontal" android:textsize="12dp" android:textstyle="bold"/>  </linearlayout> 

view onehappyrow = minflater.inflate(r.layout.one_happy_hour_row,null); textview dayofweektextview = (textview) onehappyrow.findviewbyid(r.id.dayofweektextview); textview hoursofdaytextview = (textview) onehappyrow.findviewbyid(r.id.hoursofdaytextview); 

get references here each inflated layout , set texts etc. then:

this.addview(onehappyrow); 

the class in case extends linearlayout.

each reference working now, , not last reference.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -