1

データベースからのエントリを表示しているリストビューでテキストの色を変更しようとしています。問題は、目に見えないテキストが表示されることです (または、このリストのエントリを区切る行のみが表示されます) が、エントリをクリックすると、このエントリの詳細が表示されます。ViewBinder を使わなくても表示はうまくいきます。

// map each name to a TextView
    String[] from = new String[] { "event" };
    int[] to = new int[] { R.id.countryTextView };
    conAdapter = new SimpleCursorAdapter(Clock.this, R.layout.day_plan, null, from, to);



    SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() {

        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex){    
            int getIndex = cursor.getColumnIndex("colour");
            String empname = cursor.getString(getIndex);
           tv = (TextView)findViewById(R.id.countryTextView);

            tv.setTextColor(Color.WHITE);

           if(empname.equals("Green"))
            {                   
                tv.setTextColor(Color.WHITE);
                return true;
            } 
            return false;          
        }


    };
    setListAdapter(conAdapter); // set adapter
    ((SimpleCursorAdapter) conAdapter).setViewBinder(binder);

どうすれば正常に動作するように変更できますか?

4

2 に答える 2

0

行を変更

tv = (TextView)view.findViewById(R.id.countryTextView); // <-- add 'view.'

電話

conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder)

setListAdapter(conAdapter); // set adapter
于 2016-10-26T11:37:39.330 に答える
0

テキストビューにテキストを追加する必要があります。

@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) 
{
    ((TextView) view).setTextColor(Colors.RED);
    ((TextView) view).setText(cursor.getString(cursor.getColumnIndex("YOUR-COLUMN-NAME")));
    return false;
}
于 2013-03-26T16:34:48.217 に答える