gpt4 book ai didi

android - 如何在gridview中添加复选框?所以多选是可能的

转载 作者:行者123 更新时间:2023-11-30 03:38:52 24 4
gpt4 key购买 nike

下面是我的源代码,它适用于单选我想添加复选框以选择多张图片请帮助我我该怎么做?我如何更改我的 simpleadapter?或者如何在 simpleadapter 中添加复选框??请帮助我,我很困惑

      public class FileGridActivity extends Activity {

GridView gridView;
TextView textView;
File currentParent;
File[] currentFiles;
String[] currentFilePath;
ImageButton AddPictures;
SimpleAdapter simpleAdapter;
final Context context = this;
DataBase db;
List<AppPhotosData> picList;
ProgressDialog myProgressDialog = null;
File CameraRoll;



File root;

Handler handle = new Handler(){
public void handleMessage(android.os.Message msg) {

if (msg.what == 1)
{
hideProgress();

//list.setAdapter(new AppPhotosAdapter(getApplicationContext(),activity,0,picList));
}
else if (msg.what == 2)
{
hideProgress();
}
super.handleMessage(msg);
};
};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

File photos = new File(getFilesDir(),"photos");
photos.mkdirs();

File root1 = new File("/data/data/com.newsoftwares.folderlock/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.newsoftwares.folderlock/files/"+FileName(currentFilePath[position])+"/");

Log.e("Root first",root+ " ");

currentFiles = root.listFiles();

inflateListView(currentFiles);
}
else if(currentFiles[position].isFile())
{
inflateListView(currentFiles);
}
}

});


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);
}
else
{
listItem.put("icon", files[i]);
}

listItem.put("fileName", files[i].getName());
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.setAdapter(simpleAdapter);




<!-----------main.xml------------>

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >




<!----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:orientation="horizontal"

android:padding="5dip" >



<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"

/>


</RelativeLayout>


<GridView
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:horizontalSpacing="0pt"
android:verticalSpacing="1pt"
android:numColumns="3"
android:gravity="center"
></GridView>



</LinearLayout>

最佳答案

关于android - 如何在gridview中添加复选框?所以多选是可能的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16157932/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com