I have created an app in which i had use SPenSDK to create image using canvasView. Once i create an images in the canvas view, i save the image in the SD Card "/mnt/sdcard/SmemoExample" location. Now I want to display all the images that are stores here "/mnt/sdcard/SmemoExample" in my ListView.
But i am not able to find any solution for that. So please help to solve this out. If possible with an examples.
List_view.xml file
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"/> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Clear Cache"/> </LinearLayout>
item.xml file
<?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="wrap_content"> <ImageView android:id="@+id/image" android:layout_width="50dip" android:layout_height="50dip" android:src="@drawable/ic_launcher" android:scaleType="centerCrop"/> <TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:layout_gravity="left|center_vertical" android:textSize="20dip" android:layout_marginLeft="10dip"/> </LinearLayout>
java code
public class ListActivity extends Activity { private String[] mFileStrings; private File[] listFile; ListView list; ImageAdapter adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); File file = new File(CanvasActivity.DEFAULT_APP_IMAGEDATA_DIRECTORY); if (file.isDirectory()) { listFile = file.listFiles(); mFileStrings = new String[listFile.length]; for (int i = 0; i < listFile.length; i++) { mFileStrings[i] = listFile[i].getAbsolutePath(); } } list = (ListView) findViewById(R.id.list); adapter = new ImageAdapter(this, mFileStrings); list.setAdapter(adapter); } public class ImageAdapter extends BaseAdapter { private Activity activity; private String[] data; private LayoutInflater inflater=null; public ImageLoader imageLoader; public ImageAdapter(Activity a, String[] d) { activity = a; data=d; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); imageLoader=new ImageLoader(activity.getApplicationContext()); } public int getCount() { return data.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; if(convertView==null) vi = inflater.inflate(R.layout.item, null); TextView text=(TextView)vi.findViewById(R.id.text);; ImageView image=(ImageView)vi.findViewById(R.id.image); text.setText("item "+position); imageLoader.DisplayImage(data[position], image); return vi; } }
}