我有一个变量“余额”,我在单击一个按钮时将其初始化为“0”,该按钮调用了我的自定义适配器“MyAdpater”。我的活动中有一个 EditText。当我隐藏/显示键盘时,我不会收到有关它的通知。我已经徒劳地尝试了 configChnage 方法。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Toast.makeText(Ledger.this, "Config Change has been called.", Toast.LENGTH_SHORT).show();
// Checks whether a hardware or on-screen keyboard is available
balance = 0;
ourCursor = db.getLedger(et.getText().toString(), from.getText()
.toString(), to.getText().toString());
id.clear();
adapter = new MyAdapter(Ledger.this, ourCursor, false);
lv.setAdapter(adapter);
}
(当出现键盘(dis)时不会调用此方法,因为 Toast 没有出现。)
这是我的代码
class MyAdapter extends CursorAdapter {
public MyAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
// TODO Auto-generated constructor stub
balance = 0;
}
@Override
public void bindView(View view, Context ctxt, Cursor c) {
// TODO Auto-generated method stub
TextView tv1 = (TextView) view.findViewById(R.id.tvAB1);
TextView tv2 = (TextView) view.findViewById(R.id.tvAB2);
TextView tv3 = (TextView) view.findViewById(R.id.tvAB3);
TextView tv4 = (TextView) view.findViewById(R.id.tvAB4);
TextView tv5 = (TextView) view.findViewById(R.id.tvAB5);
String date = c.getString(1);
tv1.setText(date.substring(6, 8) + "/" + date.substring(4, 6) + "/"
+ date.substring(0, 4));
tv2.setText("" + c.getDouble(3));
tv3.setText("" + c.getDouble(4));
balance = balance + c.getDouble(4) - c.getDouble(3);
tv4.setText("" + (balance));
tv5.setText((c.getDouble(3) > c.getDouble(4) ? "CR." : "DR."));
}
@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = getLayoutInflater();
return inflater.inflate(
R.layout.text_view_for_list_view_account_balance, parent,
false);
}
}
当我显示/隐藏键盘时,它不会初始化我的变量“balance = 0”的值,因此,每次显示/隐藏键盘时,balance 的值都会不断增加。每当我显示/隐藏键盘时,我都想设置 balance = 0 。有什么方法可以做到这一点吗?
请帮忙。谢谢。:)