开发者

binding to TextView

I've tried all the examples in this site that talk about binding data to a TextView but nothing solve my problem .

I have a dataBase, and TextView , I bind them together with a simple cursor adapter

        MyDataBase mDB = new MyDataBase(this);
        Cursor cursor = mDB.all(this);

        String[] from = new String[] {mDB.VALUE};
        int[] to = new int[] {R.id.text1View1};

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.main, cursor, from , to );
        adapter.setViewBinder(new myViewBinder()); 

and here is the code of the myViewBinder

public boolean setVi开发者_运维技巧ewValue(View view, Cursor cursor, int columnIndex) {

    TextView txtWelcome = (TextView) view;
    String name = cursor.getString(VALUE_ID);
    txtWelcome.setText(name);
}

can any one help me to know why there's no change in the main activity when it's lunched? what extra code I need to add ?


Try adding adapter.notifyDataSetChanged() after setting the adapter?


I believe for this to work you would have to be able to set the SimpleCursorAdapter as the adapter on the TextView but the TextView class doesn't support that operation out of the box.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜