package com.niu.readfile;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
public class Readallchecklisttxt extends Activity{
String[] fname;
ListView list;
private StringBuffer contactValue;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainallchecklisttxt);
et = (EditText) findViewById(R.id.EditText_alltxt);
Button btntest = (Button) findViewById(R.id.Button_test);
btntest.setOnClickListener(ltest);
Button btnok = (Button) findViewById(R.id.Button_ok);
btnok.setOnClickListener(lok);
Button btnadd = (Button) findViewById(R.id.Button_add);
btnadd.setOnClickListener(ladd);
list = (ListView) findViewById(R.id.list);
}
OnClickListener ltest = new OnClickListener() {
@Override
public void onClick(View v) {
showTxtNameDialog();
}
};
OnClickListener lok = new OnClickListener() {
@Override
public void onClick(View v) {
File path=new File("/data/data/com.niu.readfile/files/");
// 获取目录内所有.txt结尾的文件名字
fname=path.list(new FilenameFilter(){
public boolean accept(File dir, String name) {
if(name!=null&&name.endsWith(".txt"))
return true;
else
return false;
}
});
list.setAdapter(new ArrayAdapter<String>(Readallchecklisttxt.this, android.R.layout.simple_list_item_multiple_choice, fname));
//list.setItemsCanFocus(true);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
};
OnClickListener ladd = new OnClickListener() {
boolean ischecked;
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for (int i = 0; i < fname.length; i++) {
if (ischecked) {
et.append(fname[i]);
}
}
}
};
private void showTxtNameDialog() {
File path=new File("/data/data/com.niu.readfile/files/");
// 获取目录内所有.txt结尾的文件名字
final String[] fname=path.list(new FilenameFilter(){
public boolean accept(File dir, String name) {
if(name!=null&&name.endsWith(".txt"))
return true;
else
return false;
}
});
final boolean[] checkedItems = new boolean[fname.length];
for (int i = 0; i < fname.length; i++) {
checkedItems[i] = false;
}
new AlertDialog.Builder(this).setCancelable(false)
.setTitle("选择要选中的文本(多选)")//.setIcon(R.drawable.mq)
.setMultiChoiceItems(fname, checkedItems,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog,
int which, boolean isChecked) {
contactValue = new StringBuffer();
if(isChecked){
checkedItems[which] = true;
}
for(int i=0;i<checkedItems.length;i++){
if(checkedItems[i] == true){
String[] itemValue = fname[i].split(":");
contactValue.append(itemValue[0]).append(",");
}
}
if(contactValue.length()>0){
contactValue.deleteCharAt(contactValue.length()-1);
}
et.setText(contactValue.toString());
}
}).setPositiveButton("确认",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialoginterface, int i) {
dialoginterface.dismiss();
}
}).show();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android读写文件
共64个文件
class:29个
xml:9个
java:7个
5星 · 超过95%的资源 需积分: 15 78 下载量 4 浏览量
2010-07-23
14:39:18
上传
评论 3
收藏 157KB RAR 举报
温馨提示
Android读写文件,该文件包含Android里的读写txt文件,方便初学者使用同时欢迎大家交流经验@!
资源推荐
资源详情
资源评论
收起资源包目录
file.rar (64个子文件)
file
Savefile
bin
classes.dex 3KB
Savefile.apk 14KB
com
niu
savefile
Savefile.class 2KB
R$layout.class 388B
R$drawable.class 394B
R$attr.class 334B
R.class 477B
R$string.class 421B
resources.ap_ 10KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
values
strings.xml 167B
drawable-mdpi
icon.png 3KB
layout
main.xml 382B
assets
default.properties 465B
gen
com
niu
savefile
R.java 638B
src
com
niu
savefile
Savefile.java 2KB
.project 844B
.classpath 280B
AndroidManifest.xml 679B
Readfile
bin
classes.dex 13KB
Readfile.apk 37KB
com
niu
readfile
Readallchecklisttxt$3.class 1KB
Readalltxt.class 3KB
Readallchecklisttxt$4.class 898B
Readallchecklisttxt.class 4KB
R$layout.class 506B
R$id.class 860B
R$drawable.class 423B
Readallchecklisttxt$2.class 1KB
Readallchecklisttxt$1.class 792B
Readalltxtcontent.class 3KB
Readalltxt$2.class 848B
R$attr.class 334B
Readallchecklisttxt$6.class 904B
Readalltxt$4.class 854B
R.class 517B
Readallchecklisttxt$5.class 2KB
Readalltxtcontent$2.class 896B
R$string.class 421B
Readalltxt$3.class 2KB
Readallchecklisttxt$2$1.class 931B
Readfiletxt.class 2KB
Readalltxt$1.class 738B
Readalltxtcontent$1.class 970B
resources.ap_ 30KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 4KB
item3.jpg 16KB
values
strings.xml 167B
drawable-mdpi
icon.png 3KB
layout
mainalltxt.xml 610B
mainalltxtcontent.xml 621B
mainallchecklisttxt.xml 1KB
main.xml 1KB
assets
default.properties 465B
gen
com
niu
readfile
R.java 2KB
src
com
niu
readfile
Readfiletxt.java 3KB
Readalltxtcontent.java 2KB
Readallchecklisttxt.java 4KB
Readalltxt.java 2KB
.project 844B
.classpath 280B
AndroidManifest.xml 1KB
共 64 条
- 1
玄飞
- 粉丝: 8
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页