Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Android.os.Bundle;
Import Android.provider.MediaStore.Images.Media;
Import android.app.Activity;
Import Android.database.Cursor;
Import Android.view.Menu;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.ListView;
Import Android.widget.SimpleAdapter;
Binding listeners for the View button's Click event
View.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Empty the original data in names, Descs, filenames collection
Names.clear ();
Descs.clear ();
Filenames.clear ();
Search all picture information by Contentresolver
cursor cursor = getcontentresolver (). Query (
Media.external_content_uri, NULL, NULL, NULL, or NULL);
while (Cursor.movetonext ()) {
Get the display name of a picture
String name = cursor.getstring (Cursor.getcolumnindex (media.display_name));
Get a detailed description of the picture
String desc = cursor.getstring (Cursor.getcolumnindex (media.description));
Get the data where the picture is saved
byte[] data = Cursor.getblob (Cursor.getcolumnindex (media.data));
Add a picture name to the Names collection
Names.add (name);
Add a picture description to the Descs collection
Descs.add (DESC);
Add a picture save path to the Filenames collection
Filenames.add (new String (data, 0, data.length-1));
}
Create a list collection with the elements of the list set as map
list<map<string, string>> listItems = new arraylist<map<string,string>> ();
Converts data from a names, Descs, two collection object into the Map collection
for (int i = 0; I<names.size (); i++) {
map<string, object> listItem = new hashmap<string, object> ();
Listitem.put ("Name", Names.get (i));
Listitem.put ("desc", Descs.get (i));
Listitems.addall (ListItems);
}
Create a Simpleadapter
Simpleadapter simpleadapter = new Simpleadapter (
Mainactivity.this, ListItems, R.layout.line,
New string[]{"name", "Desc"}, new Int[]{r.id.name,r.id.desc});
Set adapter for the show ListView component
Show.setadapter (Simpleadapter);
}
});
Use ContentProvider to manage multimedia-----View all pictures in multimedia data