我有EditText
在其中的列表項,我不知道會有多少物品。當我在EditText
中輸入一些文本時,出現問題,然後向下滾動ListView
,在我再次向上滾動後,我的第一個EditText
中沒有文本,或者其他EditText
中有一些文本從ListView
。Android:EditText在ListView中滾動時丟失內容?
我試過TextWatcher
,並將數據保存到數組,但問題是ListView
中返回的視圖位置並不總是正確的,所以我從數組中丟失了一些數據。
請幫忙。
這裏是我的代碼:
public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public String[] Current;
ArrayList<String> MeterName, PreviousReading, Current_Reading;
JSONArray getArray_Meter_Reading;
public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) {
mInflater = LayoutInflater.from(context);
this.getArray_Meter_Reading = getArray_Meter_Reading;
MeterName = new ArrayList<String>();
PreviousReading = new ArrayList<String>();
for (int i = 0; i < getArray_Meter_Reading.length(); i++) {
try {
String Meter_Name = getArray_Meter_Reading.getJSONObject(i)
.getString("MeterName").toString();
String previous_Meter_Reading = getArray_Meter_Reading
.getJSONObject(i).getString("PrevMeterReading")
.toString();
MeterName.add(Meter_Name);
PreviousReading.add(previous_Meter_Reading);
// Meter[i]=MeterName.get(i);
// Previous[i]=PreviousReading.get(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public int getCount() {
return getArray_Meter_Reading.length();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.meter_reading_list, null);
holder = new ViewHolder();
holder.adp_MeterName = (TextView) convertView
.findViewById(R.id.txt_Meter_Name);
holder.adp_Previous = (TextView) convertView
.findViewById(R.id.txt_Previous);
holder.adp_Current = (EditText) convertView
.findViewById(R.id.ed_Current);
holder.adp_Current.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start,
int before, int count) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
Current[holder.ref] = s.toString();
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ref = position;
holder.adp_MeterName.setText(MeterName.get(position));
holder.adp_Previous.setText(PreviousReading.get(position));
// holder.adp_Current.setHint(MeterName.get(position));
// holder.adp_Current.setText(PreviousReading.get(position));
return convertView;
}
class ViewHolder {
TextView adp_MeterName, adp_Previous;
EditText adp_Current;
int ref;
}
}
它是什麼不同? – 2012-02-17 13:00:26
你看過我建議的代碼嗎?它首先通過代碼包含一個HashMap對象there.go! – Hiral 2012-02-17 13:01:24
我面對的是什麼問題是,當在第一個edittext中鍵入一些值,我向下滾動到列表中,顯示第一個edittext中的值是一些其他edittext框。可以爲最近三天面臨這個問題的即時通訊提供解決方案。 – 2012-02-17 13:03:30