在SimpleCursorAdapter中设置字体

时间:2014-08-02 11:46:12

标签: android simplecursoradapter android-typeface

我想在SimpleCustorAdpater中设置字体。我用这段代码实现了SimpleCustorAdpater:

    if(cur!=null&&cur.getCount() > 0)
    {
    do
     {
        String[] fromColumns = { "A_name", "T_name","D_name" };
        int[] toViews = { R.id.textView2, R.id.textView3, R.id.textView4 };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(activity,R.layout.query_cell_schedules, cur, fromColumns, toViews, 0);
        QueryFragment.listview1.setAdapter(adapter);
     }
      while(cur.moveToNext());
    }

为此,我必须覆盖SimpleCursorAdapter的ViewBinding这样的东西

SimpleCursorAdapter.ViewBinder binding=adapter.setViewBinder( new SimpleCursorAdapter.ViewBinder()
{
boolean SetViewValue(View view, Cursor cursor, int columnIndex)
{
  TextView tv1=(TextView)view.findViewById(R.id.textView1);
  TextView tv2=(TextView)view.findViewById(R.id.textView2);
  TextView tv3=(TextView)view.findViewById(R.id.textView3);

  //Setting typeface  here

  return true;
}
});

但它给了我错误Type mismatch: cannot convert from void to SimpleCursorAdapter.ViewBinder

我该如何解决?

1 个答案:

答案 0 :(得分:1)

问题是setViewBinder返回void并且您正在尝试将其设置为变量。这样做的正确方法是:

SimpleCursorAdapter.ViewBinder binding = new SimpleCursorAdapter.ViewBinder() {
    boolean SetViewValue(View view, Cursor cursor, int columnIndex) {
      TextView tv1=(TextView)view.findViewById(R.id.textView1);
      TextView tv2=(TextView)view.findViewById(R.id.textView2);
      TextView tv3=(TextView)view.findViewById(R.id.textView3);

      //Setting typeface  here

      return true;
    }
});

adapter.setViewBinder(binding);