您好我一直在尝试将缩略图添加到我使用此源构建的Fileexplorer中: https://www.javacodegeeks.com/2012/10/android-listview-example-with-image-and.html。 我无法弄清楚如何获取文件路径的缩略图。有人可以帮我解决这个问题吗?
FrontListBaseAdapter.java
public class FrontListBaseAdapter extends BaseAdapter {
private static ArrayList<FrontDetails> itemDetailsrrayList;
private LayoutInflater l_Inflater;
public FrontListBaseAdapter(Context context, ArrayList<FrontDetails> results) {
itemDetailsrrayList = results;
l_Inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return itemDetailsrrayList.size();
}
@Override
public Object getItem(int position) {
return itemDetailsrrayList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.item_details_view, null);
holder = new ViewHolder();
holder.Image = (ImageView) convertView.findViewById(R.id.photo);
holder.MsgType = (TextView) convertView.findViewById(R.id.name);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//This is where i get the path to the file
itemDetailsrrayList.get(position).getImage();
holder.Image.setImageResource(R.drawable.ic_launcher); // you can set your setter here
holder.MsgType.setText(itemDetailsrrayList.get(position).getName());
return convertView;
}
// holder view for views
static class ViewHolder {
ImageView Image;
TextView MsgType;
}}
FrontDetails.java
public class FrontDetails {
private String name;
private String filePath;
public String getImage() {
return filePath;
}
public void setImage(String filePath) {
this.filePath=filePath;
}
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}}
答案 0 :(得分:0)
我认为你可以使用这个
File imgFile = new File( itemDetailsrrayList.get(position).getImage() );
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageviewTest);
myImage.setImageBitmap(myBitmap);
}