[List of FAQs] | [Android FAQ] | [Samuh Varta]
[List of FAQs] | [Android FAQ] | [Samuh Varta]
[List of FAQs] | [Android FAQ] | [Samuh Varta]
[List of FAQs] | [Android FAQ] | [Samuh Varta]
beta jane wrote:public class demo extends Activity {
private Uri[] mUrls;
String[] mFiles=null;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.images);
File images = Environment.getDataDirectory();
File[] imagelist = images.listFiles(new FilenameFilter(){
@Override
public boolean accept(File dir, String name)
{
return ((name.endsWith(".jpg"))||(name.endsWith(".png")));
}
});
mFiles = new String[imagelist.length];
for(int i= 0 ; i< imagelist.length; i++)
{
mFiles[i] = imagelist[i].getAbsolutePath();
}
mUrls = new Uri[mFiles.length];
for(int i=0; i < mFiles.length; i++)
{
mUrls[i] = Uri.parse(mFiles[i]);
}
Gallery g = (Gallery) findViewById(R.id.addToDictionary);
g.setAdapter(new ImageAdapter(this));
g.setFadingEdgeLength(40);
}
public class ImageAdapter extends BaseAdapter{
int mGalleryItemBackground;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount(){
return mUrls.length;
}
public Object getItem(int position){
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent){
ImageView i = new ImageView(mContext);
i.setImageURI(mUrls[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(260, 210));
return i;
}
private Context mContext;
}
}
Hi,this a modified code to display images.
but i get this error that images in layout is not resolved which is highlighted in red
Please help![]()
Thanks in advance
Monu Tripathi wrote:Hi,
Welcome to JavaRanch!
A few things:
1. Do you have an images.xml file in your layout folder?
2. Can you check your imports? The imported "R.java" file should belong to one in your package; the import statement should not read import android...R;
You are getting the error because the compiler cannot find the images file.
Note: please use Code tags when posting code; the post becomes easier to read.
machines help you to do more, but experience less. Experience this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|