列表视图项目 onclick 从数据库传递包
我使用 onitemclick 方法创建了一个列表视图,以将从数据库获取的捆绑包传递到另一个活动。
但其他活动没有按照我的预期获得捆绑包,有人可以检查我的代码并告诉我原因吗?谢谢
mDB = new ChannelDB(this); String[] 列 = {mDB.KEY_ID、mDB.KEY_POSTER、mDB.KEY_CHANNEL、mDB.KEY_PATH、mDB.KEY_DBLINK}; 字符串表 = mDB.channelS_TABLE; c = mDB.getHandle().query(表、列、null、null、null、null、null); 开始管理光标(c); SimpleCursorAdapter 适配器 = new SimpleCursorAdapter(this, R.layout.channelview, c、 新字符串[] {mDB.KEY_POSTER,mDB.KEY_CHANNEL,mDB.KEY_DBLINK}, new int[] {R.id.poster, R.id.channel, R.id.douban}); 适配器.setViewBinder(new ChannelViewBinder()); 通道列表.setAdapter(适配器); Channellist.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterViewparent, View view, int 位置,长 id) { c.moveToPosition(位置); 意图intent = new Intent(); intent.setClass(HDtvs.this,Showlist.class); 捆绑包 = new Bundle(); Bunde.putString("路径",mDB.KEY_PATH); Bunde.putString("cname",mDB.KEY_CHANNEL); Bunde.putString("dblink",mDB.KEY_DBLINK); /* 将Bundle对象分配给Intent */ 意图.putExtras(bunde); 启动活动(意图); } });
显示列表.java
> public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* 设定layout为newslist.xml */
setContentView(R.layout.showlist);
ChannelName=(TextView) findViewById(R.id.cname);
back=(Button) findViewById(R.id.back);
likebutton=(Button) findViewById(R.id.share);
Intent intent=this.getIntent();
Bundle bunde = intent.getExtras();
/* 取得Bundle对象中的数据 */
String path = bunde.getString("path");
String title = bunde.getString("cname");
String dblink = bunde.getString("dblink");
Bundle bunde2= new Bundle();
bunde2.putString("dblink",dblink);
/* 调用getRss()取得解析后的List */
li=getRss(path);
ChannelName.setText(title);
/* 设定自定义的MyAdapter */
setListAdapter(new MyAdapter(this,li, bunde2));
`
I made a listview with an onitemclick method to deliver bundle which it get from the database to another activity.
But the other activity didn't get the bundle as I expected, can someone check my code and tell why? thx
mDB = new ChannelDB(this); String[] columns = {mDB.KEY_ID, mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_PATH, mDB.KEY_DBLINK}; String table = mDB.channelS_TABLE; c = mDB.getHandle().query(table, columns, null, null, null, null, null); startManagingCursor(c); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.channelview, c, new String[] {mDB.KEY_POSTER, mDB.KEY_CHANNEL, mDB.KEY_DBLINK}, new int[] {R.id.poster, R.id.channel, R.id.douban}); adapter.setViewBinder(new ChannelViewBinder()); channellist.setAdapter(adapter); channellist.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { c.moveToPosition(position); Intent intent = new Intent(); intent.setClass(HDtvs.this,Showlist.class); Bundle bunde = new Bundle(); bunde.putString("path",mDB.KEY_PATH); bunde.putString("cname",mDB.KEY_CHANNEL); bunde.putString("dblink",mDB.KEY_DBLINK); /* 将Bundle对象assign给Intent */ intent.putExtras(bunde); startActivity(intent); } });
showlist.java
> public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* 设定layout为newslist.xml */
setContentView(R.layout.showlist);
ChannelName=(TextView) findViewById(R.id.cname);
back=(Button) findViewById(R.id.back);
likebutton=(Button) findViewById(R.id.share);
Intent intent=this.getIntent();
Bundle bunde = intent.getExtras();
/* 取得Bundle对象中的数据 */
String path = bunde.getString("path");
String title = bunde.getString("cname");
String dblink = bunde.getString("dblink");
Bundle bunde2= new Bundle();
bunde2.putString("dblink",dblink);
/* 调用getRss()取得解析后的List */
li=getRss(path);
ChannelName.setText(title);
/* 设定自定义的MyAdapter */
setListAdapter(new MyAdapter(this,li, bunde2));
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样尝试:
然后在你的第二堂课中得到这个包,如下所示:
You can try like this:
and then in your second class get this bundle like this:
你确定“putExtras”是对的吗?你可以在这一行断点吗:
也许你把一个空字符串放入buddle中?
are u sure "putExtras" is right? can u break point at this line :
maybe you put a empty string into buddle?