涉及知识点:ListView、SimpleAdapter和ListView点击事件等
文章目录
一、运行图
二、代码
文章内容
一、运行图

运行效果:

二、代码
1.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:divider="@color/cardview_shadow_start_color"
android:dividerHeight="5dp"/>
</LinearLayout>
2.logic.xml
<?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="horizontal">
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="150dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:

本文介绍了如何在Android中使用ListView和SimpleAdapter创建一个列表,并实现列表项的点击事件以及根据点击位置动态改变背景颜色。通过MySimpleAdapter的重写,展示了如何设置特定项高亮显示和数据绑定。
最低0.47元/天 解锁文章
1353

被折叠的 条评论
为什么被折叠?



