嗨,我知道這個問題已經出現在這裏,但答案並沒有幫助我。好的,我有一個活動,列表視圖綁定到ArrayListAdapter爲我的類ZamowieniePoz。Android ListView和EditText
public class ZamowieniePoz {
private int _idZamowienie;
private String _plu;
private String _nazwa;
private String _ilosc;
private String _jm;
private String _uwagi;
private String _dataSync;
private int _isSync; }
這是我的ListView definitione:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical">
<ListView
android:id="@+id/listView"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@id/listView" >
<Button
android:id="@+id/btnWyslij"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="WYŚLIJ ZAMÓWIENIE" />
<Button
android:id="@+id/btnPowrotZamowienieAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="POWRÓT" />
</LinearLayout>
這是ListView的行:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtPlu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/txtIlosc"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/txtPlu"
android:layout_marginLeft="25sp"
android:lines="1"
android:inputType="numberDecimal" />
</RelativeLayout>
這是ArrayListAdapter:
public class ZamowieniePozArrayAdapter extends ArrayAdapter<ZamowieniePoz> {
Context context;
int layoutResourceId;
ArrayList<ZamowieniePoz> data=null;
public ZamowieniePozArrayAdapter(Context context, int layoutResourceId, ArrayList<ZamowieniePoz> data) {
super(context, layoutResourceId, data);
this.layoutResourceId=layoutResourceId;
this.context=context;
this.data = data;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
ZamowienieHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row=inflater.inflate(layoutResourceId, parent, false);
holder = new ZamowienieHolder();
holder.txtPlu = (TextView)row.findViewById(R.id.txtPlu);
holder.txtIlosc=(EditText)row.findViewById(R.id.txtIlosc);
holder.txtIlosc.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
data.get(position).setIlosc(s.toString());
}
});
row.setTag(holder);
}
else{
holder = (ZamowienieHolder)row.getTag();
}
ZamowieniePoz zamowieniePoz = data.get(position);
holder.txtPlu.setText(zamowieniePoz.getPlu());
holder.txtIlosc.setText(zamowieniePoz.getIlosc());
return row;
}
static class ZamowienieHolder {
TextView txtPlu;
EditText txtIlosc;
}
}
這是我如何綁定適配器的ListView:
final DbHandler db = new DbHandler(ZamowienieAddActivity.this);
listView = (ListView) findViewById(R.id.listView);
arrayZamowieniePoz = db.getAllZamowienie();
arrayAdapterZamowieniePoz = new ZamowieniePozArrayAdapter(this, R.layout.zamowienie_add_list_items, arrayZamowieniePoz);
listView.setAdapter(arrayAdapterZamowieniePoz);
因此,這是它。問題是listView的第一行重複最後一行。我認爲這行代碼有些問題data.get(position).setIlosc(s.toString());在getTextChange中。
請幫幫我我不知道什麼是錯的。謝謝。
我加了一個TextWatcher和addTextChangeListener之前進行removeTextChangeListener和我doensn't改變任何東西。你可以發表一個例子如何以你的方式做到這一點。也許我做錯了什麼。 THX – silaros88
@ user2440158編輯我的帖子,舉例 – nicopico
我的上帝。尼科皮科你做了我的一天。有用 !!! – silaros88