【Android新手笔记三】listview

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值