0

カスタムアダプタ「MyAdpater」を呼び出すボタンの「0」onClickに初期化する変数「balance」があります。アクティビティに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);
}

(このメソッドは、トーストが表示されないため、キーボードが(表示されない)表示された場合は呼び出されません。)

これは私のコードです

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に設定したい。これを行う方法はありますか?

助けてください。ありがとう。:)

4

1 に答える 1

0

World of ListView (またはTurboCharge Your UI ) で、Android の Romain Guy は、アダプターのビルド順序に依存できないと述べています。トップダウン、ボトムアップ、または中間のどこかから開始していずれかの方向に移動する可能性があります。この設計上の選択は、効率に関連しています。

balanceしたがって、ビルド順序に依存しない計算方法を見つける必要があります...


newView()また、データベース内のすべての行に対して呼び出されるわけではないため、現在のアダプタはスクロールをサポートしていません。ListView (または Spinner など) で呼び出される回数はnewView()、ユーザーの画面に収まる行数に関連しています。

于 2013-01-25T16:20:02.060 に答える