通知键盘 [英] Notification for keyboard

查看:186
本文介绍了通知键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量'平衡',这我要初始化一个按钮,它调用我的自定义适配器的0的onClickMyAdpater。我在活动已经一个EditText。当我隐藏/显示键盘,我没有得到通知了。我妄图configChnage方法了。

I have a variable 'balance' which I'm initializing to '0' onClick of a button which calls my custom adapter 'MyAdpater'. I've an EditText in my activity. When I hide/show the keyboard, I don't get notified about it. I've vainly tried configChnage Method already.

 @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)出现,因为面包不会出现这个方法没有被调用。)

(This method isn't called when keyboard (dis)appears because the Toast doesn't appear.)

这是我的code

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);
    }
}

它不初始化我的变量的值,资产负债= 0',因为我显示/隐藏键盘和放大器;因此,平衡的价值只是不断提高我每次显示/隐藏键盘的时间。我想设置余额= 0,每当我显示/隐藏键盘。有没有什么方法来做到这一点?

It doesn't initialize the value of my variable 'balance = 0' as I show/hide the keyboard & therefore, the value of balance just keeps on increasing every time I show/hide the keyboard. I want to set balance = 0 whenever I show/hide the keyboard. Is there any method to do this?

请帮忙。谢谢。 :)

推荐答案

世界(或武装您的UI )Android的罗曼盖伊指出,你不能依靠适配器的构建顺序。它可以建立自上而下,自下而上,或在任一方向的中间和旅行开始的地方;这种设计的选择涉及到效率。

In World of ListView (or TurboCharge Your UI) Android's Romain Guy states that you cannot rely on the Adapter's build order. It may build top-down, bottom-up, or start somewhere in the middle and travel in either direction; this design choice relates to efficiency.

所以,你需要找到一个方法来计算余额不是构建顺序上的依赖......

So you need to find a way to calculate balance that is not reliant on the build order...

此外,您的当前适配器不支持滚动,因为 NewView的()不要求你的数据库的每一行。时间的数 NewView的()在你的ListView(或微调等)被调用涉及到多少行用户的屏幕上适合。

Also your current Adapter does not support scrolling, since newView() is not called for every row in your database. The number of time newView() gets called in your ListView (or Spinner, etc) relates to how many rows fit on the user's screen.

这篇关于通知键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆