android - How to set edittext editable dynamically by click an imagebutton? -


i list dynamically string values arraylist edittexts loop, , imagebuttons next every edittext. want this: when click imagebutton, corresponsive edittext editable. here code activity:

linearlayout container = (linearlayout) findviewbyid(r.id.container); layoutinflater layoutinflater = (layoutinflater) getbasecontext().getsystemservice(context.layout_inflater_service); final view showproduct = layoutinflater.inflate(r.layout.row_show_product, null);  (int = 0; < product.size(); ++i) {     final edittext edt_row_show_product = (edittext) showproduct.findviewbyid(r.id.edt_row_show_product);     edt_row_show_product.settext(product.get(i));     imagebutton ib_row_show_product_edit_icon = (imagebutton)showproduct.findviewbyid(r.id.ib_row_show_product_edit_icon);      ib_row_show_product_edit_icon.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             //container.getparent()...;         }     });      container.addview(showproduct); }   

i made quick app make requirement work. please take look.

i had code working in fragment if working in activity please make required changes.

fragment code:

package viewtest.myapplication;  import android.app.activity; import android.app.fragment; import android.content.context; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.view.viewgroup.layoutparams; import android.view.windowmanager; import android.view.inputmethod.inputmethodmanager; import android.widget.button; import android.widget.edittext; import android.widget.imagebutton; import android.widget.linearlayout; import android.widget.textview;  import java.util.arraylist; import java.util.arrays;   /**  * placeholder fragment containing simple view.  */ public class mainactivityfragment extends fragment {      public fragvisibilityinterface minterface = null;      private linearlayout showproduct, edittextsll;      @override     public void onattach(activity activity) {         super.onattach(activity);         minterface = new fragvisibilityinterface() {             @override             public void togglefragvisibility() {              }         };     }      public mainactivityfragment() {     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_main, container, false);         //button testbtn = (button) rootview.findviewbyid(r.id.testbutton);          /*testbtn.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 hidefrag();             }         }); */         string [] myarray = getresources().getstringarray(r.array.populate_array);         arraylist<string> product = new arraylist<>(arrays.aslist(myarray));              (int = 0; < product.size(); ++i){             view showprod = createnewtextview(product.get(i));             linearlayout edittextll = (linearlayout) rootview.findviewbyid(r.id.edittextsll);             edittextll.addview(showprod);             showprod = null;         }         return rootview;     }      /*private void hidefrag() {         secondactivityfragment secfrag = new secondactivityfragment();         getfragmentmanager().begintransaction().add(r.id.fragment, secfrag, "secfrag").commit();         getfragmentmanager().begintransaction().hide(this).commit();     }*/      private view createnewtextview(string text) {         layoutinflater layoutinflater = (layoutinflater) getactivity().getsystemservice(context.layout_inflater_service);         view showproduct = layoutinflater.inflate(r.layout.edit_text_layout, null);         final edittext edt_row_show_product = (edittext) showproduct.findviewbyid(r.id.edittext);         edt_row_show_product.settext(text);         button ib_row_show_product_edit_icon =(button) showproduct.findviewbyid(r.id.button);          ib_row_show_product_edit_icon.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                  edt_row_show_product.requestfocusfromtouch();                 inputmethodmanager imm = (inputmethodmanager) getactivity().getsystemservice(context.input_method_service);                 imm.showsoftinput(edt_row_show_product, inputmethodmanager.show_implicit);              }         });         return showproduct;     }      public interface fragvisibilityinterface{         public void togglefragvisibility();     } } 

edittext , button layout

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:id="@+id/linearlayout">     <edittext         android:id="@+id/edittext"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         />     <button         android:id="@+id/button"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="edit"         /> </linearlayout> 

main fragment layout

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"     android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivityfragment">      <textview         android:id="@+id/textview"         android:text="@string/hello_world" android:layout_width="wrap_content"         android:layout_height="wrap_content" />     <button         android:id="@+id/testbutton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/textview"         android:text="button"/>      <linearlayout         android:id="@+id/edittextsll"         android:layout_below="@id/testbutton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:orientation="vertical"></linearlayout>  </relativelayout> 

the code may little rough around edges made real quick. please make relevant changes. hope helps! :)


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -