ListView Item点击事件跳转详情界面
2015-05-07 21:51
2171 查看
有好久都没有碰安卓了,考试加五一双组合也真是让人蛋疼。好在都平安的度过了,所以又有时间gun回来弄弄我的小博客(虽然没多少人看= =)。看了之前做的几个小demo,模式都差不多,但是每次写的时候都要在看一遍知识点,(笨DIE)。这次mark一下,成为自己的东西!
-----------------------------------------------------吐槽分割线-----------------------------------------------------------------
这次写的是ListView 每个Item的点击事件跳转详情界面的知识。
我的DEMO是用ListView展示SQLite里的每一条数据。(这个内容之后再总结一篇)。每一个Item里有TextView显示数据库里的信息。
首先,给Item绑定监听事件,然后使用bundle类,顾名思义,就是将信息捆成一捆传递给下一个ACTIVITY。
这里用到bundle里的putString(String key,String value)方法,具体API解释:
Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.(key值是另一个Activity需要用到的关键值,value是你需要传进去的值)。
之后就是想下一个活动传递数据操作:
新建一个意图关联当前的活动和下一个活动:Intent intent = new Intent(MainActivity.this,detailInfo.class);
调用Intent的putExtras(Bundle extras)方法:将之前的bundle参数传进去即可。
startActivity(intent)就ok。
下一个Activity接受数据,模式如下:
其中的getString方法中传入的就是之前的key值。这样就能在TextView里面显示Item想要传的数据
----------------------------------------------------正经分割线-------------------------------------------------------------------------
自己都觉得好不专业的样子= =!!!只是一个超级简单的传递数据功能。之后这类知识会出一个姊妹篇什么的,剧本已经写好,就差女主了(什么鬼!)。
好了,写完感觉自己萌萌哒,喝杯百事压压惊~bye - bye
-----------------------------------------------------吐槽分割线-----------------------------------------------------------------
这次写的是ListView 每个Item的点击事件跳转详情界面的知识。
我的DEMO是用ListView展示SQLite里的每一条数据。(这个内容之后再总结一篇)。每一个Item里有TextView显示数据库里的信息。
首先,给Item绑定监听事件,然后使用bundle类,顾名思义,就是将信息捆成一捆传递给下一个ACTIVITY。
这里用到bundle里的putString(String key,String value)方法,具体API解释:
Inserts a String value into the mapping of this Bundle, replacing any existing value for the given key. Either key or value may be null.(key值是另一个Activity需要用到的关键值,value是你需要传进去的值)。
之后就是想下一个活动传递数据操作:
新建一个意图关联当前的活动和下一个活动:Intent intent = new Intent(MainActivity.this,detailInfo.class);
调用Intent的putExtras(Bundle extras)方法:将之前的bundle参数传进去即可。
startActivity(intent)就ok。
listView.setOnItemClickListener(new OnItemClickListener(){ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub Information info = list.get(position); Bundle bundle = new Bundle(); bundle.putString("fromWhere", info.getFromWhere()); bundle.putString("toWhere", info.getToWhere()); bundle.putString("time",info.getTime()); bundle.putString("content", info.getContent()); Intent intent = new Intent(MainActivity.this,detailInfo.class); intent.putExtras(bundle); finish(); startActivity(intent); } });
下一个Activity接受数据,模式如下:
Textview fromWhere=(TextView)findViewById(R.id.fromWhere); Bundle b=getIntent().getExtras(); //获取Bundle的信息 String info=b.getString("fromWhere"); fromWhere.setText("起始地:"+info);
其中的getString方法中传入的就是之前的key值。这样就能在TextView里面显示Item想要传的数据
----------------------------------------------------正经分割线-------------------------------------------------------------------------
自己都觉得好不专业的样子= =!!!只是一个超级简单的传递数据功能。之后这类知识会出一个姊妹篇什么的,剧本已经写好,就差女主了(什么鬼!)。
好了,写完感觉自己萌萌哒,喝杯百事压压惊~bye - bye
相关文章推荐
- Android实现ListView显示信息,点击每个item,跳转到相应界面
- 安卓小日记练习(8)listview的另一个item点击事件的界面和数据保存
- Android使用ListView构造复杂界面,响应点击事件,通过Intent跳转activity
- android中通过网络请求数据显示在Listview中,面对许多的item,如何给每个item设置点击事件以跳转到不同的activity
- Android listView中点击item或Item中控件跳转对应的详情页面的实现(商品详情查看)
- Androd中 listView点击每一个 Item里面的状态,跳转到相对应的不同 界面
- listview的item跳转的下一个界面点击删除数据,并返回更新listview
- ListView中item点击事件失效的解决办法
- Android-ListView所包含的item里面的控件点击事件
- Android中ListView的item不能响应点击事件的原因
- Android下listview每个Item中包含有按钮,为什么在点击某一行按钮的时候,同时有多行button触发了响应事件?
- listview中的item要获取到点击事件
- listview中的item和button的点击事件的冲突
- ListView中的item的按照和item点击事件并存
- 点击listView条目,给点中条目加上上下边框(变换背景),item布局控件的点击事件
- 区分listview的item和Button的点击事件
- 实现xlistview+xutils展示数据之后点击item跳转页面显示图片缩放和放大
- Android ListView 获取不到Item点击事件
- android捕获ListView中每个item点击事件
- Kotlin初体验(二)--点击事件与界面跳转