Android之ListView列表视图和界面跳转实现

本文通过实例详细讲解了如何在Android中使用ListView创建列表视图,并实现点击列表项后跳转到不同界面的功能。步骤包括在布局文件配置ListView,以及在string资源文件中管理文本,最后展示了点击列表项后的效果。
摘要由CSDN通过智能技术生成

本篇文章通过一个例子实现ListView列表视图并且点击不同的项进入不同的界面


第一步,我们需要在布局文件中设置ListView属性

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="?android:attr/listDivider" />
    
    <ListView
        android:id="@+id/listView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

那么在ListView里面需要什么内容呢


第二步,添加界面

1.在string里面设置文字,其实在xml文件或者activity界面里面我们也可以直接写文字,但是如果将文字都写在string里面,统一管理文字,这对以后我们修改起来会方便很多

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">ListViewDemo</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>
    
    <string name="demo1_name">测试1</string>
    <string name="demo1_title">测试1名称</string>
    <string name="demo1_desc">测试1描述:这是一个测试例子</string>
    
    <string name="demo2_name">测试2</string>
    <string name="demo2_title">测试2
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值