0

コードをカスタム リスト アダプター ビュー (このリストには 11 個のアイテムしかありません) に変換し、ビューホルダーはここでは役に立ちません。

@Override 
public View getView(int position, View convertView, ViewGroup parent){
    LayoutInflater inflater  = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if( convertView == null ){ // for fast view google io http://www.youtube.com/watch?v=wDBM6wVEO70
    convertView = inflater.inflate(R.layout.single_transaction,parent,false);
    }
    TextView phone_number = (TextView) convertView.findViewById(R.id.phone_number_show);
    TextView transaction_summary = (TextView) convertView.findViewById(R.id.transaction_summary_show);
    TextView transaction = (TextView) convertView.findViewById(R.id.transaction_show);

    Transactions single_transaction = (Transactions)  getItem(position);

    phone_number.setText(String.valueOf(single_transaction.get_phone_number()));
    transaction_summary.setText(single_transaction.get_transaction_summary());

    int single_transaction_value = single_transaction.get_transaction();

    if(single_transaction_value < 0) {

        transaction.setBackgroundColor(Color.parseColor("#098AAA"));
    }

    transaction.setText(String.valueOf(single_transaction_value));

    return convertView;

}

ここで、条件が xml で定義された textview のデフォルトの色 (skyblue) を変更
した場合、single_transaction_value < 0 の場合、textview の色が #098AAA (薄緑)
に変更され、色が期待どおりに変化しません。

トップバーの色が正しいことに注意してください。電話番号の灰色。白い背景上のテキスト。条件に応じて、取引のスカイブルーまたはライトグリーンの色。奇妙な動作は、xml で定義されているデフォルトのスカイブルーからコードで定義されているライトグリーンに色が変化することです。

ここで if 条件が少し変更され、else が追加されました

if(single_transaction_value < 0) {

        transaction.setBackgroundColor(Color.parseColor("#098AAA"));
    }
else {
        transaction.setBackgroundColor(Color.parseColor("#76BB51"));
    }

期待どおりに色が変化するようになりました。

これはどのように..

4

0 に答える 0