项目需要,使用ListView把存储卡中的某个文件夹下的文件列出来,并且可以对这些文件进行删除处理。
1、布局文件line.xml
用来布局ListView每一项的样式
一个图片文件、一个文本显示、一个选择框,其中CheckBox要做失焦处理,因为我们想要的是点击后进入ListView的监听函数
失焦处理:
android:clickable="false"android:focusable="false"android:focusableInTouchMode="false"
android:id="@+id/icon" android:layout_width="40dp" android:layout_height="40dp" android:paddingLeft="10dp"/>android:id="@+id/file_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/icon" android:textSize="30dp" android:textColor="@android:color/white"/> android:id="@+id/checkBox" android:text="" android:layout_width="78dp" android:layout_height="wrap_content" android:layout_alignBottom="@+id/file_name" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:focusable="false" android:clickable="false" android:focusableInTouchMode="false"/>
2、布局文件main.xml
用ListView显示文件,按钮操作文件,共4个按钮:确认删除,全部选择,取消选择,取消删除。
android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/line" android:layout_alignParentTop="true"> android:id="@+id/line" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal">
3.、Main.java文件
//定义存放在drawable文件夹下的file.png文件import static com.nialt.www.listview.R.drawable.file;public class MainActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemLongClickListener, AdapterView.OnItemClickListener { //定义组件 ListView listView; Button affirm; Button selectAll; Button cancelselect; Button cancel; List
4、实现效果,真机运行的,直接拍图了
- 拥抱Android(安卓)Studio:从ADT到Android(安卓)Studio
- Android&Java的学习新的等
- Android(安卓)Framework 导入到AS中
- 2013.11.04(3)——— android 创建公共库以及使用公共库
- Android反向进度条(ProgressBar)的实现——从右到左的进度条
- Launcher3 总结
- Android(三):远程Service基本操作
- Android(安卓)Styles & Themes(上)——Style
- Android(安卓)自定义线程池
随机推荐
-
Activity-RelativeLayout
-
Android:EditText 多行显示及所有属性
-
android ListView 去除下划线和选中模式
-
Android:Material Design(三) 动画
-
Android系统自带样式Android:theme
-
android Style属性介绍
-
Android(安卓)textAppearance的属性设置
-
android:inputType参数类型说明
-
Android应用开发——系统自带样式Android
-
Google的Android设备别名