没有显示SimpleCursorAdapter.ViewBinder文本 [英] SimpleCursorAdapter.ViewBinder text not showing

查看:220
本文介绍了没有显示SimpleCursorAdapter.ViewBinder文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在堆积的问题,我无法找到解决方案。

I have been stacked at a problem and i can not find the solution.

我有一个数据库,我加载使用一个ListView SimpleCursorAdapter

I have a database and i load a listview using SimpleCursorAdapter.

我要改变依赖于数据库(incOrExp)的列的值的文本的颜色。

这是我的列表项:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10dp"
android:background="#afeeee" >

<TextView 
android:id="@+id/incomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:paddingTop="5dp"
android:paddingLeft="20dp"
android:paddingBottom="2dp"
android:textSize="20sp"
android:textColor="#b22222" />

<TextView
android:id="@+id/amountTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/currencyTextView"
android:paddingTop="10dp"
android:paddingRight="5dp"
android:paddingBottom="5dp"
android:textColor="#0000cd"
android:textSize="20sp" />

<TextView
android:id="@+id/currencyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="5dp"
android:textColor="#0000cd"
android:textSize="20sp"
android:text="€" />

<TextView
android:id="@+id/dateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/incomeTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:paddingTop="2dp"
android:paddingLeft="20dp"
android:paddingBottom="5dp"
android:textColor="#0000cd"
android:textSize="12sp" />

</RelativeLayout>

我想改变(的TextView)的颜色的 amountTextView 使用SimpleCursorAdapter.ViewBinder()

I want to change the color of the (TextView)amountTextView using SimpleCursorAdapter.ViewBinder()

这是我的code:

    String[] from = new String[] {"inCategory","inAmount","inDateFormat"}; 
    int[] to = new int[] { R.id.incomeTextView, R.id.amountTextView, R.id.dateTextView}; 

    incomeAdapter = new SimpleCursorAdapter (this, R.layout.income_list_item, null, from, to);

    incomeAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
          if (view.getId() == R.id.amountTextView)
            { 
              int incOrExpIndex = cursor.getColumnIndex("incOrExp");
              int incOrExp = cursor.getInt(incOrExpIndex);
              if (incOrExp==1) {
              TextView tvColor = (TextView)view;
              tvColor.setTextColor(Color.YELLOW);
              }
              else {
                  TextView tvColor = (TextView)view.findViewById(R.id.amountTextView);
                  tvColor.setTextColor(Color.RED);
              }
             return true;

        }
          return false;}

    });

    incomeListView.setAdapter(incomeAdapter); 

哪里是我的错吗?

Where is my fault?

感谢您提前。

推荐答案

我已经找到了答案......

I have found the answer...

我不得不设置颜色之后,我不得不过多的setText ....

I had to set the color and after that i had to setText too....

incomeAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
          if (view.getId()==R.id.amountTextView)
            { 
              int incOrExpIndex = cursor.getColumnIndex("incOrExp");
              int incOrExp = cursor.getInt(incOrExpIndex);

            switch(incOrExp) {
                case 0: 
                    TextView tv0 = (TextView)view;
                    tv0.setTextColor(Color.BLUE);
                    tv0.setText(cursor.getString(cursor.getColumnIndex("inAmount")));
                    break;
                case 1: 
                    TextView tv1 = (TextView)view;
                    tv1.setTextColor(Color.RED);
                    tv1.setText(cursor.getString(cursor.getColumnIndex("inAmount")));
                    break;
              }
             return true;

        }
          return false;}
    });

我要感谢谁试图解决这个问题的人......

I want to thank people who have tried to solve this problem...

这篇关于没有显示SimpleCursorAdapter.ViewBinder文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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