运用BaseAdapter自定义一个经典的ListView

本文详细介绍了如何通过自定义BaseAdapter来配置一个经典的ListView。主要步骤包括:1) 设计并配置xml文件main.xml和item.xml,main.xml中包含ListView;2) 创建自定义适配器MyBaseAdapter,继承自BaseAdapter;3) 创建主Activity Main,继承自Activity进行相关配置;4) 更新Manifest文件。最后展示了完成后的效果。
摘要由CSDN通过智能技术生成

首先来配置xml文件,main.xml和item.xml。

main.xml:主界面布局,包含一个ListView组件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
 <ListView 
     android:id="@+id/listView"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
     
 </ListView>   

</LinearLayout>

</pre><h1>item.xml:自定义ListView子项的布局文件,包含一个Imageview和两个TextView。</h1><pre class="html" name="code"><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="wrap_content"
    android:layout_margin="10dp"
    android:orientation="horizontal"
     >
    <ImageView
        android:id="@+id/item_img"
        android:layout_width="80dp"
        android:layout_height="40dp"
        android:scaleType="fitXY"
        android:layout_margin="10dp"
         />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"  
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值