键盘通知

时间:2013-01-25 16:10:19

标签: android android-cursoradapter

我有一个变量'balance',我正在初始化为'0'onClick按钮调用我的自定义适配器'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 = 0。有没有办法做到这一点?

请帮忙。谢谢。 :)

1 个答案:

答案 0 :(得分:0)

World of ListView(或TurboCharge Your UI)Android中,Romain Guy表示您不能依赖适配器的构建顺序。它可以自上而下,自下而上,或从中间的某个地方开始,向任何一个方向行进;这种设计选择与效率有关。

所以你需要找到一种方法来计算不依赖于构建顺序的balance ......


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

相关问题