Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add a checkbox in my gridview?
    text
    copied!<p>how do i add checkbox in my code? so user select multiple pictures using checkbox in gridview what do i do? I just want to add a checkbox in my gridview what do i do?</p> <pre><code>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&lt;?&gt; 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&lt;Map&lt;String, Object&gt;&gt; listItems = new ArrayList&lt;Map&lt;String, Object&gt;&gt;(); for (int i = 0; i &lt; files.length; i++) { Map&lt;String, Object&gt; listItem = new HashMap&lt;String, Object&gt;(); 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 }); } </code></pre> <p><strong>line.xml</strong></p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" &gt; &lt;ImageView android:id="@+id/icon" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;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" /&gt; &lt;/RelativeLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload