我在ListView
上遇到麻烦,每一项都有EditText
。
在Fragment
加载时,“应付金额”列的所有初始值都与“票价”列相同。
在此图像上,我更改了值。
但是当我向下滚动(共10个项目)并再次向上滚动时,我注意到我已编辑的行,该值返回到初始值
我试图检查
的答案Listview edittext value changing on scrolling和ListView baseadapter class implement TextWatcher
但是行为保持不变。
这是我的getView()
@Override
public View getView(final int position, View v, ViewGroup viewGroup) {
decimalFormat = new DecimalFormat("###,##0.00");
dbHelper = new DBHelper(c);
sqldb = dbHelper.getWritableDatabase();
dbManager = new DBManager(c);
dbManager.open();
getDeviceInfo();
getTripDetails();
final PaymentList2ViewHolder viewHolder;
if (v == null) {
v = LayoutInflater.from(c).inflate(R.layout.item_payment, viewGroup, false);
viewHolder = new PaymentList2ViewHolder(v);
v.setTag(viewHolder);
} else {
viewHolder = (PaymentList2ViewHolder) v.getTag();
}
if (getCount() == 0) {
viewGroup.removeAllViewsInLayout();
} else {
Payment2Item s = (Payment2Item) getItem(position);
viewHolder.tvId.setText(s.getSeatID());
viewHolder.tvSeatNo.setText(s.getSeatNo());
viewHolder.tvPassengerName.setText(s.getfName() + " " + s.getlName());
viewHolder.tvPassengerType.setText(s.getPassengerType());
viewHolder.tvPassengerID.setText(s.getPassengerID());
viewHolder.tvFareAmount.setText(s.getFare());
viewHolder.txtAmountToPay.setHint(s.getPayment());
viewHolder.tvDiscountedAmount.setText(s.getDiscount());
//getting the data in JSONObject form
JSONObject dataObject = null;
try {
dataObject = objAllSched.getJSONObject("data");
JSONArray schedArray = dataObject.getJSONArray("schedules");
Log.e("schedArray", String.valueOf(schedArray));
if (dataObject.length() != 0) {
for (int i = 0; i < schedArray.length(); i++) {
JSONObject object = schedArray.getJSONObject(i);
String id = null;
id = object.getString("id");
Log.e("object ", String.valueOf(object));
if (id.toString().equalsIgnoreCase(scheduleId)) {
JSONArray faresArray = object.getJSONArray("fares");
Log.e("fare array", String.valueOf(faresArray));
for (int sab = 0; sab < faresArray.length(); sab++) {
JSONObject object2 = faresArray.getJSONObject(sab);
String name = null;
name = object2.getString("name");
if (s.getPassengerType().equalsIgnoreCase(name)) {
price = Double.parseDouble(object2.getString("price"));
s.setFare(String.valueOf(price));
viewHolder.tvFareAmount.setText(decimalFormat.format(price));
viewHolder.txtAmountToPay.setText(decimalFormat.format(price));
itemArrayPayment2List.get(position).setPayment(viewHolder.txtAmountToPay.getText().toString());
Log.e("getxt", viewHolder.txtAmountToPay.getText().toString());
}
}
}
}
}
//adding TextWatcher
viewHolder.txtAmountToPay.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
//updating the setter setPayment()
itemArrayPayment2List.get(position).setPayment(editable.toString());
}
});
} catch (JSONException e) {
e.printStackTrace();
}
viewHolder.txtAmountToPay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewHolder.txtAmountToPay.setText("");
}
});
if (is_rebook == 1) {
viewHolder.txtAmountToPay.setEnabled(false);
viewHolder.txtAmountToPay.setClickable(false);
}
}
return v;
}
我可以知道这是什么问题吗?谢谢!