我想創建對象的EditText n個創建的每個對象的EditText ......所以使用LayoutInflater IM做,在它運行至ň...的意見被添加到佈局,但環如果我想一個addTextChangeListener添加到每個的EditText對象,聽者僅被添加到的最後一個對象...其關閉的問題,我怎麼能解決這個問題?添加addTextChangeListener在循環
LinearLayout ll=(LinearLayout) findViewById(R.id.i1);
LayoutInflater li=(LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
for(int i=0;i<3;i++){
v=li.inflate(R.layout.addit, null); //v is a View declared as private member of the class
t=(TextView) v.findViewById(R.id.a1);//t is TextView declared as private member
EditText e=(EditText) v.findViewById(R.id.e1);
e.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
public void afterTextChanged(Editable arg0) {
ret(v, t);
}
});
ll.addView(v);
}
我RET功能
public void ret(View v,TextView t){
EditText e=(EditText) v.findViewById(R.id.e1);
t.setText(e.getText());
}
主要XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/i1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
addit.xml看起來像這樣
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/l2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical" >
<TextView
android:id="@+id/a1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:text="" />
<EditText
android:id="@+id/e1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
</LinearLayout>
聽者只監聽在過去的變化EditText視圖的...如何讓它聽取所有三個EditText視圖? 感謝..
由於解決了這個問題.... – karyboy 2012-01-03 11:37:52