Jump to content

[Resolvido] GridView Sdcard


DNPereira
 Share

Recommended Posts

Pessoal, o problema e o seguinte. Não estou a conseguir ir buscar o imagem ao sdcard.

public class LayoutOneGridView extends BaseAdapter {
 private Context mContext;
 public LayoutOneGridView(Context c) {
   mContext = c;
 }

 public int getCount() {
   return LayoutOne.themeInfo.size();
 }

 public Object getItem(int position) {
   return null;
 }

 public long getItemId(int position) {
   return 0;
 }

 public View getView(int position, View convertView, ViewGroup parent) {
   ImageView imageView=new ImageView(mContext);
   try
   {
     AssetManager assetmanager = mContext.getAssets();
     LayoutInflater inflater = LayoutInflater.from(mContext);
     convertView = inflater.inflate(R.layout.buttontext, null);
     BufferedInputStream themeButtonBuf = new BufferedInputStream(assetmanager.open(LayoutOne.themeInfo.get(position)+"/themeButton.png"));
     Bitmap themeButton = BitmapFactory.decodeStream(themeButtonBuf);
     imageView = (ImageView)convertView.findViewById(R.id.themeButton);
     imageView.setImageBitmap(themeButton);
     BufferedInputStream themeButtonTextBuf = new BufferedInputStream(assetmanager.open(LayoutOne.themeInfo.get(position)+"/themeButtonText.png"));
     Bitmap themeButtonText = BitmapFactory.decodeStream(themeButtonTextBuf);
     imageView = (ImageView)convertView.findViewById(R.id.themeButtonText);
     imageView.setImageBitmap(themeButtonText);
     BufferedInputStream themePreviewBuf = new BufferedInputStream(assetmanager.open(Layout      One.themeInfo.get(position)+"/previewTag.png"));
     Bitmap themePreview = BitmapFactory.decodeStream(themePreviewBuf);
     imageView = (ImageView)convertView.findViewById(R.id.themePreview);
     imageView.setImageBitmap(themePreview);
     FileInputStream themeSdcardBuf = new FileInputStream(Environment.getExternalStorageDirectory()+java.io.File.separator+LayoutOne.themeInfo.get(position)+"/themeButton.png");
     Bitmap themeSdcard = BitmapFactory.decodeStream(themeSdcardBuf);
     imageView = (ImageView)convertView.findViewById(R.id.sdCardImage);
     imageView.setImageBitmap(themeSdcard);
     themeSdcardBuf.read();
     themeButtonTextBuf.close();
     themeButtonBuf.close();
     themePreviewBuf.close();
     themeSdcardBuf.close();
   }
   catch (IOException e)
   {
     e.printStackTrace();
   }
   return convertView;
 }
}

quando troco o arralist pelo nome da pasta, ele coloca lá a imagem.

obrigado

Link to comment
Share on other sites

Aqui esta

public View getView(int position, View convertView, ViewGroup parent) {
 ImageView imageView=new ImageView(mContext);
 try
 {
   AssetManager assetmanager = mContext.getAssets();
   LayoutInflater inflater = LayoutInflater.from(mContext);
   convertView = inflater.inflate(R.layout.buttontext, null);
   BufferedInputStream themeButtonBuf = new BufferedInputStream(assetmanager.open(LayoutOne.themeInfo.get(position)+"/themeButton.png"));
   Bitmap themeButton = BitmapFactory.decodeStream(themeButtonBuf);
   imageView = (ImageView)convertView.findViewById(R.id.themeButton);
   imageView.setImageBitmap(themeButton);
   BufferedInputStream themeButtonTextBuf = new BufferedInputStream(assetmanager.open(LayoutOne.themeInfo.get(position)+"/themeButtonText.png"));
   Bitmap themeButtonText = BitmapFactory.decodeStream(themeButtonTextBuf);
   imageView = (ImageView)convertView.findViewById(R.id.themeButtonText);
   imageView.setImageBitmap(themeButtonText);
   BufferedInputStream themePreviewBuf = new BufferedInputStream(assetmanager.open(LayoutOne.them    eInfo.get(position)+"/previewTag.png"));
   Bitmap themePreview = BitmapFactory.decodeStream(themePreviewBuf);
   imageView = (ImageView)convertView.findViewById(R.id.themePreview);
   imageView.setImageBitmap(themePreview);
   FileInputStream themeSdcardBuf = new FileInputStream(Environment.getExternalStorageDirectory()+java.io.File.separator+LayoutOne.themeInfo.get(position)+"/themeButton.png");
   Bitmap themeSdcard = BitmapFactory.decodeStream(themeSdcardBuf);
   imageView = (ImageView)convertView.findViewById(R.id.sdCardImage);
   imageView.setImageBitmap(themeSdcard);
   themeSdcardBuf.read();
   themeButtonTextBuf.close();
   themeButtonBuf.close();
   themePreviewBuf.close();
   themeSdcardBuf.close();
 }
 catch (IOException e)
 {
   e.printStackTrace();
 }


 try
 {
   FileInputStream(Environment.getExternalStorageDirectory()+java.io.File.separator+LayoutOne.themeInfo.get(position)+"/themeButton.png");
   Bitmap themeSdcard = BitmapFactory.decodeStream(themeSdcardBuf);
   imageView = (ImageView)convertView.findViewById(R.id.sdCardImage);
   imageView.setImageBitmap(themeSdcard);
 }
 catch (IOException e)
 {
   e.printStackTrace();
 }

 return convertView;
}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.