如何显示存储在我的SD卡的特定位置在列表视图中的图像 [英] How to show images in list view that are stored in my SD Card particular location
问题描述
我已经创建了一个应用程序中,我不得不使用SPenSDK使用canvasView创造的形象。有一次,我创建的画布视图的图像,我将图像保存在SD卡到/ mnt / SD卡/ SmemoExample的位置。现在我想显示所有的商店这里的到/ mnt / SD卡/ SmemoExample在我的ListView中的图像。
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文件
<?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文件
<?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;
}
}
}
推荐答案
答案是上述问题,对方的回答引用。
Answer is for reference of the above question and other answer.
只要看看 LazyList 项目。现在,我们做了一些修饰它。
Just take a look at LazyList project. Now we make a some modification in it..
MainActivity.java
private String[] mFileStrings;
private File[] listFile;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File file = new File("<Directory path from sdcard>");
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 LazyAdapter(this, mFileStrings);
list.setAdapter(adapter);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(listener);
}
在 ImageLoader.java
private Bitmap getBitmap(String url)
{
File f = new File(url);
//from SD cache
Bitmap b = decodeFile(f);
if (b != null)
{
return b;
}
return null;
}
这篇关于如何显示存储在我的SD卡的特定位置在列表视图中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!