Android 键盘提示

Android 键盘提示,android,android-cursoradapter,Android,Android Cursoradapter,我有一个变量“balance”,单击一个调用自定义适配器“MyAdpater”的按钮,我会将其初始化为“0”。我的活动中有一个编辑文本。当我隐藏/显示键盘时,我不会得到通知。我已经徒劳地尝试了配置方法 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Toast.makeText(Ledger.thi

我有一个变量“balance”,单击一个调用自定义适配器“MyAdpater”的按钮,我会将其初始化为“0”。我的活动中有一个编辑文本。当我隐藏/显示键盘时,我不会得到通知。我已经徒劳地尝试了配置方法

 @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。有什么方法可以做到这一点吗

请帮忙。谢谢。:)

在(或)Android的Romain Guy中指出,您不能依赖适配器的构建顺序。它可以自上而下,自下而上,或者从中间开始,沿着任何方向行进;这种设计选择与效率有关

因此,您需要找到一种方法来计算不依赖于构建顺序的
平衡



另外,当前适配器不支持滚动,因为数据库中的每一行都不调用
newView()
。在ListView(或微调器等)中调用
newView()
的时间与用户屏幕上的行数有关。

在BindAdapter中添加此数据无效,因为每次滚动适配器时,它都会增加我的变量“balance”。为什么以及何时增加
balance
?@Sam:c.getDouble(4)-c.getDouble(3)!=这是我连续犯的第二个错误,我的头肯定在别的地方了……:)但我的问题是。。为什么在键盘出现和消失时调用newView()?因为根据定义,只有在布局第一次膨胀时才会调用newView()。是吗?好的,山姆,谢谢。那么,有没有办法使用CustomAdapter计算余额?我可以使用不同类型的ArrayList和BaseAdapter来实现这一点,但这将导致大量代码的更改,因为我在许多类中使用相同的逻辑/我建议使用CursorAdapter,这比将所有数据转换为ArrayList更有效。如果上面的配置更改不起作用,您可以向数据库中添加一个新列来跟踪此数据,或在适配器的构造函数中循环光标,以创建余额数组列表,并在
newView()
中使用此列表,将数据放在光标内。