【Android新手笔记三】listview
来源:互联网 发布:java数组的冒泡排序法 编辑:程序博客网 时间:2024/06/08 09:33
listview显示列表项,点击不同项,跳转到 不同页面。
先在values文件夹下新建一个xml文件,然后定义一个string_array,作为列表项。
<string-array name="childfile_list"> <item>预防接种卡</item> <item>新生儿家庭访视记录表</item> <item>1岁以内儿童健康检查记录表</item> <item>1~2岁儿童健康检查记录表</item> <item>3~6岁儿童健康检查记录表</item> </string-array>之后在listview所在的activity中写Java代码。采用arrayadapter的方式,对确定的选项进行显示。
public class child_management extends AppCompatActivity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.child_file); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array .childfile_list, android.R.layout.simple_list_item_1); adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); ListView lv = (ListView) findViewById(R.id.listView); lv.setAdapter(adapter); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //点击事件 Intent intent = null; switch (position) { case 0: intent = new Intent(child_management.this, vaccination.class);break; case 1: intent = new Intent(child_management.this,new_born.class);break; case 2: intent = new Intent(child_management.this,under_1year_visit.class);break; case 3: intent = new Intent(child_management.this,between1and2years.class);break; case 4: intent = new Intent(child_management.this,between3and6years.class);break; } startActivity(intent); } }); }}
0 0
- 【Android新手笔记三】listview
- Android之ListView的个人笔记。(新手必看)
- (Android学习笔记三)自定义ListView
- 新手学习之android listView
- 【Android开发新手的学习笔记】使用LruCache对ListView进行优化
- [Android新手学习笔记23]-如何使用ListView展示列表数据
- Android学习笔记--ListView的三种使用方式
- Android学习笔记(三)--ListView与RecyclerView
- Android 学习笔记(三):ListView的使用
- Android ListView(三)
- Android 新手listview小示例(一)
- Android 新手listview小示例(二)
- Android ListView用法(简洁新手专用)
- 致新手 android中ScrollView嵌套listview
- android 新手开发笔记(个人)
- 新手Android学习笔记 04
- 【Java新手笔记三】Struts2学习
- Android中Listview(三)--圆角listview
- C#中常用的几种读取XML文件的方法
- 结构光测量------相机的选择
- 国外计算机核心期刊
- java多线程和队列实例
- Android可适配不规则tab的PageIndicator
- 【Android新手笔记三】listview
- eclipse批量替换单词
- android实现弹窗的方式汇总
- Shell脚本基础学习(二)----脚本基础命令、变量以及规则
- 『linux』解决chrome/chromium提示could't load plugin,无法播放视频问题
- linux MTU过大导致无法远程top,vi等操作
- 布局与控件(五)-Toast吐司与布局的抽象标签merge include ViewStub
- Neural networks and deep learning materials
- Android:自定义简洁dialog