Android ListView简单使用
最近的项目中用到了Listview,这里记录一下我的使用过程。
1 我的使用场景
在做项目的时候需要做一个历史记录的页面,这个应用每天会在固定的文件夹中生成一个txt文件,只需要把文件夹里面的内容显示在UI界面上,点击某个选项的时候再将文档中的内容显示再UI上就可以,问题比较简单,参考了几篇博客后顺利搞定。主要用到的是ListView控件,这里记录一下。
2 具体实现
首先看布局文件,这里写了两个布局,一个是整体的菜单布局,一个是菜单中的每个选项的布局,首先看整体菜单布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:fadingEdge="vertical"
android:background="#EDEDED">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="1px"
android:divider="#B8B8B8"
android:id="@+id/history_listview">
</ListView>
</LinearLayout>
</ScrollView>
这里使用了简单的Scrollview
再加上一个ListView
,再来看选项的布局:
<LinearLayout xmlns:android=