1

Hello i have been trying to add thumbnails to my Fileexplorer which i have built from this source: https://www.javacodegeeks.com/2012/10/android-listview-example-with-image-and.html. And I cant figure out how to get the thumbnail for the filepath. Could someone help me out on that?

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;
}}
engin
  • 15
  • 4
  • stack over flow question https://stackoverflow.com/questions/4181774/show-image-view-from-file-path – Syed Qasim Ahmed Jun 09 '18 at 19:38
  • `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); }` – Syed Qasim Ahmed Jun 09 '18 at 19:40
  • Thanks, Thumbnails are shown now, but now I'm trying to figure out how to check if the path is a folder, so i can add an folder icon... any clue? – engin Jun 09 '18 at 21:09
  • https://stackoverflow.com/questions/12780446/check-if-a-path-represents-a-file-or-a-folder – Syed Qasim Ahmed Jun 09 '18 at 21:24

1 Answers1

0

I think you can use this

    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);
 }
Syed Qasim Ahmed
  • 1,352
  • 13
  • 24