EditText 객체를 n 개 만들고 싶습니다. LayoutInflater를 사용하여 n까지 실행되는 루프에서이를 수행합니다. 뷰는 레이아웃에 추가되지만 각 EditText 객체에 addTextChangeListener를 추가하려는 경우 리스너는 마지막 객체에만 추가됩니다. 종료 문제는 어떻게 해결할 수 있습니까?루프에 생성 된 각 EditText 객체에 addTextChangeListener를 추가하십시오.
<?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>
과 같습니다
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이다 EditText보기 중 ... 세 개의 EditText보기를 모두 듣게하려면? 감사합니다 ...
덕분에 해결되었습니다 .... – karyboy