1
我有一個文件選擇器(根據需要工作),但我想在適當的時候將縮略圖添加到列表中。它適用於前幾個圖像,但隨機文件(和文件夾)不是圖像的項目,不應該有縮略圖採取已經加載的隨機圖像。整個文件列表最終在重複滾動後拍攝圖像。Android列表視圖隨機顯示圖像
這是一個列表視圖的已知問題嗎?有沒有顯示縮略圖的標準方式?我的代碼是否被破壞?
以下是爲每個列表項分配文件名和縮略圖的代碼 - 該類擴展了ArrayAdapter
。
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater) c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(id, null);
}
final Option o = items.get(position);
if (o != null)
{
TextView t1 = (TextView) v.findViewById(R.id.TextView01);
TextView t2 = (TextView) v.findViewById(R.id.TextView02);
ImageView img1 = (ImageView) v.findViewById(R.id.imageView1);
try
{
if(o.getData()!="Folder" && (o.getPath().contains(".jpg") || o.getPath().contains(".gif") || o.getPath().contains(".png")))
img1.setImageBitmap(getPreview(o.getPath()));
}
catch (Exception e)
{
Log.w("Image failed in File Viewer", e);
}
if (t1 != null)
t1.setText(o.getName());
if (t2 != null)
t2.setText(o.getData());
}
return v;
}