Android 请帮助我如何定制gridview

Android 请帮助我如何定制gridview,android,Android,我在代码中使用了一个简单的适配器。我正在从文件路径填充GridView。下面是我的代码,它是有效的。现在我想在gridview中添加一个复选框。我该怎么做?我应该如何修改我的代码?我找到的所有示例都从库中导入图像,但我需要从文件路径导入它们。如果一个文件是一个目录,我还需要显示一个目录图标,否则显示一个图像 GridView gridView; TextView textView; File currentParent; File[] currentFiles; SimpleAdapter si

我在代码中使用了一个简单的适配器。我正在从文件路径填充
GridView
。下面是我的代码,它是有效的。现在我想在gridview中添加一个复选框。我该怎么做?我应该如何修改我的代码?我找到的所有示例都从库中导入图像,但我需要从文件路径导入它们。如果一个文件是一个目录,我还需要显示一个目录图标,否则显示一个图像

GridView gridView;
TextView textView;
File currentParent;
File[] currentFiles;
SimpleAdapter simpleAdapter;
File root1;
File root;

root1 = new File("/data/data/com.myexample.lock/files/");

currentParent = root1;
currentFiles = root1.listFiles();

currentFilePath = new String[currentFiles.length];
int count = 0;

for (File f : currentFiles) {
    currentFilePath[count] = f.getAbsolutePath();
    count++;
}

gridView = (GridView) findViewById(R.id.grid);
gridView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (currentFiles[position].isDirectory()) {
            root = new File("/data/data/com.myexample.lock/files/" + FileName(currentFilePath[position]) + "/");
            currentFiles = root.listFiles();
            inflateListView(currentFiles);
        } else if (currentFiles[position].isFile()) {
            openFile(currentFiles[position]);
        }
    }
});


private void inflateListView(File[] files) {
    List<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();

    for (int i = 0; i < files.length; i++) {
        Map<String, Object> listItem = new HashMap<String, Object>();
        if (files[i].isDirectory()) {
            listItem.put("icon", R.drawable.folder);
            listItem.put("fileName", files[i].getName()+"("+files[i].list().length+")");
        } else {
            listItem.put("icon", files[i]);
        }

        listItems.add(listItem);
    }

    simpleAdapter = new SimpleAdapter(this, listItems, R.layout.line,new String[] { "icon", "fileName" }, new int[] { R.id.icon, R.id.file_name });
}
GridView-GridView;
文本视图文本视图;
当前父文件;
文件[]当前文件;
simpledapter simpledapter;
文件根1;
文件根目录;
root1=新文件(“/data/data/com.myexample.lock/files/”;
currentParent=root1;
currentFiles=root1.listFiles();
currentFilePath=新字符串[currentFiles.length];
整数计数=0;
对于(文件f:currentFiles){
currentFilePath[count]=f.getAbsolutePath();
计数++;
}
gridView=(gridView)findViewById(R.id.grid);
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
如果(currentFiles[position].isDirectory()){
root=新文件(“/data/data/com.myexample.lock/files/”+文件名(currentFilePath[position])+”/”;
currentFiles=root.listFiles();
充气列表视图(当前文件);
}else if(currentFiles[position].isFile()){
openFile(当前文件[位置]);
}
}
});
私有void inflateListView(文件[]文件){
List listItems=new ArrayList();
对于(int i=0;i
R.layout.line.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="horizontal"
    android:padding="5dip" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

       <TextView
        android:id="@+id/file_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/icon"
        android:paddingLeft="5dp"
        android:textColor="#000000"
        android:textSize="12dp" />

 </RelativeLayout>


请参阅链接。在应用程序中使用复选框自定义gridview。

你听说过句子的概念吗?@hayyaanam请尽量避免在问题中使用缩写词和缩写词,如plzz、im等。。你不是在给你的朋友写信,而是在向其他专业人士寻求帮助。用正确的大写字母写出正确的句子。你能给出一个示例文件来填充网格吗?我的所有代码都在那里吗?你的意思是我能把我的代码寄给你吗?给我你的电子邮件地址我的代码在上面你可以看到上面我曾经这样调用grid那个代码也是我的你给我的解决方案但问题是我使用simpleadapter那个代码使用自定义适配器不区分当前文件是目录还是文件?如果是目录显示文件夹图标,否则显示图像我如何像在你的代码衍射??