绑定到 TextView
我已经尝试过本网站中讨论将数据绑定到 TextView 的所有示例 但没有解决我的问题。
我有一个 dataBase 和 TextView ,我用一个简单的光标适配器将它们绑定在一起
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());
,这是 myViewBinder 的代码,
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
TextView txtWelcome = (TextView) view;
String name = cursor.getString(VALUE_ID);
txtWelcome.setText(name);
}
任何人都可以帮助我知道为什么主活动在午餐时没有变化? 我需要添加什么额外的代码?
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 setViewValue(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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在设置适配器后添加
adapter.notifyDataSetChanged()
?Try adding
adapter.notifyDataSetChanged()
after setting the adapter?我相信要使其工作,您必须能够将 SimpleCursorAdapter 设置为 TextView 上的适配器,但 TextView 类不支持开箱即用的该操作。
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.