安卓基础学习 Day 6|常用控件---列表视图+古诗查看

目录

列表视图4要素

四种是适配器

古诗查看

古诗列表

1.主布局资源文件

2.诗歌列表项模板

3.字符串资源文件

4.主界面代码

5.启动应用、查看效果

古诗内容模板

1.内容模板的主布局资源文件

2.修改主界面代码实现跳转​编辑

3.修改内容界面 

处理长古诗词


 

列表视图4要素

  1. 列表控件
  2. 适配器(数组适配器、简单适配器、游标适配器、基适配器……)
  3. 数据源(数组、列表、游标……)
  4. 列表项模板(平台资源、用户自定义)

四种是适配器

列表视图(ListView),它是AdapterView的孙子类,要通过适配器作为梁桥来绑定数据源。
有四种适配器可以使用:

1.数组适配器(ArrayAdapter)

2.简单适配器(SimpleAdapter)

3.简单游标适配器(SimpleCursorAdapter)

4.基适配器(BaseAdapter)

古诗查看

古诗列表

1.主布局资源文件

·示例代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/background"
    android:padding="15dp"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/lvPoemTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="#aaaaaa"
        android:dividerHeight="0.5dp" />


</LinearLayout>

·实现效果

2.诗歌列表项模板

·创建模板

 

·示例代码

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tvPoemTitle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:minHeight="80dp"
    android:textColor="#0000ff"
    android:textSize="25sp" />

3.字符串资源文件

·示例代码

<resources>
    <string name="app_name">阅读古诗</string>

    <string-array name="titles">
        <item>静夜思</item>
        <item>登鹳雀楼</item>
        <item>相思</item>
        <item>听弹琴</item>
        <item&
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小鲁不吃猪蹄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值