gpt4 book ai didi

java - 将缩略图添加到我的自定义适配器

转载 作者:太空宇宙 更新时间:2023-11-04 10:23:52 25 4
gpt4 key购买 nike

您好,我一直在尝试将缩略图添加到我从此源构建的 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;
}}

最佳答案

我认为你可以使用这个

    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);
}

关于java - 将缩略图添加到我的自定义适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50777825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com