Android : update particular edittext in listview

on Sunday, September 7, 2014


I have two edittext in a row of listview and on change value of one edittext i want to update the value of second edittext accordingly but doing this it updates the values of other row's edittext also how can i acheive this for the particular row i want to only. here is my sample code for this



public View getView(int position, View view, ViewGroup parent) {



if (view == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.my_row, null);
EditText et1 = (EditText) view.findViewById(R.id.et);

//attach the TextWatcher listener to the EditText
et1.addTextChangedListener(new MyTextWatcher(view));

}
//text change listener goes here
public void afterTextChanged(Editable s) {



EditText et2 = (EditText) view.findViewById(R.id.EditText01);


et2.setText("somevalue");

}


here on text change of first edittext i want to change the value of second edittext in the same row but it is updating the values of other rows also How can i fix this The row layout code simply contains two text boxes only. code for xml is below



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="6dip">

<EditText android:id="@+id/et" android:layout_width="50sp"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:inputType="number"
android:layout_alignParentTop="true" android:ems="10" />

<EditText
android:id="@+id/EditText01"
android:layout_width="50sp"
android:layout_height="wrap_content"
android:layout_marginLeft="23dp"
android:ems="10"
android:inputType="number" >

<requestFocus />
</EditText>

</RelativeLayout>

0 comments:

Post a Comment