I am using view paper for image gallery, able to see all the images on swipe.
Here I want to set the image as wallpaper by clicking the "Set as wallpaper" button.
Below are the difficulties I am facing:
I am able to set the image as wallpaper successfully, but with constant image
Ex: R.drawable.picture3.But at run time when the images are loaded at each
turn different image will be displayed so cannot give this constant value
R.drawable.picture3.
How do I get the run time image id which is displayed?
Trying to achieve on click "Set as wallpaper" should set the current image
as wallpaper.
Note : v.getId()=R.drawable.picture1 not worked here both gave different value
Below is my code:
Context context;
Integer[] imageIDs = {
R.drawable.picture1,
R.drawable.picture2,
R.drawable.picture3,
R.drawable.picture4,
R.drawable.picture5,
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
Button button=(Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaperManager.setResource(R.drawable.picture3);
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(),
"Image is clicked-"+v.getBackground(), Toast.LENGTH_SHORT).show();
}
});
}
public class ImageAdapter extends PagerAdapter{
Context context;
int currentPosition;
private int[] GalImages = new int[] {
R.drawable.picture1,
R.drawable.picture2,
R.drawable.picture3,
R.drawable.picture4,
R.drawable.picture5,
};
ImageAdapter(Context context){
this.context=context;
}
#Override
public int getCount() {
return GalImages.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(R.dimen.abc_action_bar_content_inset_material);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(GalImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</android.support.v4.view.ViewPager>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#cccccc"
android:text="#string/set_as_wallpaper" />
</RelativeLayout>
I don't want to achieve this in instantiateItem method in image adapter.
It's simple.If I got it correct then you want to set the image as wallpaper after clicking the button.Then here is the logic
viewPager.setOnPageChangeListener(new OnPageChangeListener() {
#Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
curruntPosition=arg0; //Here you can the position
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
And then
button.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v) {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallpaperManager.setResource(imageIDs[curruntPosition]);
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(getApplicationContext(),
"Image is clicked-"+v.getBackground(), Toast.LENGTH_SHORT).show();
}
});
Edit:
If you want to get the current viewable image from the viewpager
Maintain a list of images that are added dynamically say imageList then
int currentItem =viewPager.getCurrentItem();
Drawable drawable = getResource.getDrawable(imageList[currentItem]);
Bitmap bm =((BitmapDrawable) drawable).getBitmap();
Related
I have a custom listview with custom adapter. I want to click on the items of listview and do something. The OnItemClickListener does not works. But I implemented OnLongItemClickListenerand it works perfectly.
MainActivity
public class MainActivity extends Activity {
ArrayList<Product> products = new ArrayList<Product>();
Adapter listviewAdapter; //custom adapter object
ListView listview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView) findViewById(R.id.lvMain);
listview.setLongClickable(true);
listviewAdapter = new Adapter(this, products);
listview.setAdapter(listviewAdapter);
listview.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) { //this works
Toast.makeText(getApplicationContext(), "Long pressed", Toast.LENGTH_SHORT).show();
return false;
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { //does not work
Toast.makeText(getApplicationContext(), " pressed", Toast.LENGTH_SHORT).show();
}
});
}
UPDATE custom adapter Adapter
public class Adapter extends BaseAdapter {
Context ctx;
LayoutInflater lInflater;
ArrayList<Product> objects;
TextView itemname,itemprice;
Adapter(Context context, ArrayList<Product> products) {
ctx = context;
objects = products;
lInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return objects.size();
}
#Override
public Object getItem(int position) {
return objects.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.item, parent, false);
}
Product p = getProduct(position);
itemname= ((TextView) view.findViewById(R.id.tvDescr));
itemname.setText(p.name);
itemprice=((TextView) view.findViewById(R.id.tvPrice));
itemprice.setText(p.price + "");
CheckBox cbBuy = (CheckBox) view.findViewById(R.id.cbBox);
cbBuy.setOnCheckedChangeListener(myCheckChangList);
cbBuy.setTag(position);
cbBuy.setChecked(p.selected);
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
view.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return false;
}
});
return view;
}
Product getProduct(int position) {
return ((Product) getItem(position));
}
ArrayList<Product> getBox() {
ArrayList<Product> selected = new ArrayList<Product>();
for (Product p : objects) {
if (p.selected)
selected.add(p);
}
return selected;
}
OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
getProduct((Integer) buttonView.getTag()).selected = isChecked;
}
};
}
custom listview item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants">
<CheckBox
android:id="#+id/cbBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" >
</CheckBox>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tvDescr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" >
</TextView>
</LinearLayout>
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/lvMain"
android:layout_width="match_parent"
android:layout_height="0dp"
android:longClickable="true">
</ListView>
to your text views and check box
android:focusable="false"
THis is because of your CheckBox. You can solve like this:
Add an id to your Linearlayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
android:id="#+id/main_layout">
And in your getView
LinearLayout main_layout = (LinearLayout)view.findViewById(R.id.main_layout));
main_layout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
listview .performItemClick(view,
listview.getPositionForView(view),
listview.getPositionForView(view));
}
});
Edit:
Use following code for long click
main_layout.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View arg0) {
listview.performLongClick();
return true;
}
});
You can give android:onClick attribute in xml :
<CheckBox
android:id="#+id/cbBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:onClick="onCheckboxClicked" />
This will work when you check or uncheck Checkbox.
Reason why onClick do not work, but onLongClick works :
You have applied onListItemClickListener over your list view row so when you were clicking on checkbox, the event was consumed by this listener
listview.setOnItemClickListener(new OnItemClickListener() {
Update :
in getView() :
// for list row
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Log.d("onClick","row click");
}
});
// for list row check box
view.cbBuy.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Log.d("onClick","checkbox click");
}
});
In MainActivity :
Remove this part :
/* listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) { //does not work
Toast.makeText(getApplicationContext(), " pressed", Toast.LENGTH_SHORT).show();
}
}); */
Whether checkbox has property android:focusable="true" or false this code will run
This is working compiled and run code
Thank you
#Amsheer your code works. But for that you had to change the custom adapter and write the actions for onClick events in it. I wanted to write the onClick events in the ManiActivity. I found a workaround. I removed this from custom adapter
view.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return false;
}
});
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
I'm using the PhotoView library to have a slide view of images. That's easy. Then I wanted set as wallpaper the image I wanted, maybe on click in a button but I have a problem! The library seems that not allows create a layout but only its in this way.
<com.ex.paper.HackyViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
So i can't add any button. I need detect the right array position and in some way set that image as wallpaper.. So far the code is this:
`public class MainActivity extends Activity
{
Bitmap bitmap;
int lastImageRef;
private static final String ISLOCKED_ARG = "isLocked";
private ViewPager mViewPager;
private static MenuItem menuLockItem;
private WallpaperManager wallpaper;
private static int[] sDrawables = { R.drawable.wallpapertwo, R.drawable.twixkatfirst, R.drawable.wallpaper,
R.drawable.sfondo, R.drawable.wallpapertre};
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mViewPager = (HackyViewPager) findViewById(R.id.view_pager);
setContentView(mViewPager);
mViewPager.setAdapter(new SamplePagerAdapter());
if (savedInstanceState != null) {
boolean isLocked = savedInstanceState.getBoolean(ISLOCKED_ARG, false);
((HackyViewPager) mViewPager).setLocked(isLocked);
}
}
static class SamplePagerAdapter extends PagerAdapter {
#Override
public int getCount() {
return sDrawables.length;
}
#Override
public View instantiateItem(ViewGroup container, int position) {
PhotoView photoView = new PhotoView(container.getContext());
photoView.setImageResource(sDrawables[position]);
WallpaperManager wallpaper = WallpaperManager.getInstance(container.getContext());
/*Toast number = Toast.makeText(container.getContext(), "wallpaper number "+position, Toast.LENGTH_LONG);
number.show();*/
// Now just add PhotoView to ViewPager and return it
container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
try
{
wallpaper.setResource(sDrawables[position]);
}
catch (IOException e)
{
}
return photoView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
}`
Now, in the try catch, I can set the wallpaper through position but without tapping any button!! And of course it's not a good way. Any solution? Maybe a button in the actionbar? But I can't find the array position at that point.
You can use FrameLayout:
<FrameLayout...>
<com.ex.paper.HackyViewPager/>
<Button/>
<FrameLayout/>
In onCreate:
setContentView(your.layout.with.frameLayout);
mViewPager = (HackyViewPager) findViewById(R.id.view_pager);
mButton = (Button) findViewById(R.id.button);
mButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
wallpaper.setResource(sDrawables[mViewPager.getCurrentItem()]);
}
});
}
I have an activity with ViewPager. I'm using it to swipe images. I also have a save button, and I need to save the current image to SD card. But I get an error. Here's my XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rl_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true" >
<android.support.v4.view.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/bSave"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="Save"
android:layout_alignParentLeft="true"
android:textSize="24sp"
android:padding="0dp"
android:background="#drawable/buttons" />
</RelativeLayout>
And here's my class:
public class Photo_gallery extends Activity implements OnClickListener{
Button save;
final File myDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/Images/");
boolean success = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_gallery);
save = (Button) findViewById(R.id.bSave);
final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
save.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
final String fname = "StyleMe-" + n + ".png";
myDir.mkdirs();
File image = new File(myDir, fname);
BitmapDrawable drawable = (BitmapDrawable) viewPager.getBackground();
Bitmap bitmap = drawable.getBitmap();
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (success) {
Toast.makeText(getApplicationContext(), "Image saved with success at /sdcard/Pictures/SexyImages",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error during image saving", Toast.LENGTH_LONG).show();
}
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse
("file://"
+ Environment.getExternalStorageDirectory())));
}
});
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {
R.drawable.p1,
R.drawable.p2,
R.drawable.p3,
.
.
.
.
R.drawable.p108
};
#Override
public int getCount() {
return mImages.length;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = Photo_gallery.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
I get error on this line (java.lang.NullPointerException):
Bitmap bitmap = drawable.getBitmap();
why didn't you do like that :
on button Save Clicklistener :
int currentItem =viewPager.getCurrentItem();
Drawable drawable = getResource.getDrawable(mImages[currentItem]);
Bitmap bm =((BitmapDrawable) drawable).getBitmap();
I have an activity with some images and I'm using swipe to load the next image. I need when I touch the image to show a button, for image saving. How can I do that? Here's my code:
public class Photo_gallery extends Activity{
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.photo_gallery);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImagePagerAdapter adapter = new ImagePagerAdapter();
viewPager.setAdapter(adapter);
}
private class ImagePagerAdapter extends PagerAdapter {
private int[] mImages = new int[] {
R.drawable.p1,
R.drawable.p2,
R.drawable.p3,
R.drawable.p4,
.
.
.
R.drawable.p108
};
public int getCount() {
return mImages.length;
}
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
public Object instantiateItem(ViewGroup container, int position) {
Context context = Photo_gallery.this;
ImageView imageView = new ImageView(context);
int padding = context.getResources().getDimensionPixelSize(
R.dimen.padding_medium);
imageView.setPadding(padding, padding, padding, padding);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
EDIT:
My XML code:
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
If you just want it to show a button on the screen when you click the image, you can put a button in your layout with the parameter android:visibility="gone".
Then, when the user clicks the image (just put an OnClickListener() for the ImageView), call button.setVisibility(View.VISIBLE); to show the button. Then when the user performs any other action and you want to hide the button again, call button.setVisibility(View.GONE);
I am trying to get path of photo from gallery which in grid view. this gallery consists of each thumbnail with attached checkbox. Here is the whole code:
public class GridGallery extends Activity
{
ArrayList<String>list;
AlertDialog.Builder alert;
private Button send;
GridView gridView;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_gallery);
DataModel dbModel = new DataModel(this);
list = dbModel.selectAll();
alert = new AlertDialog.Builder(GridGallery.this);
send = (Button)findViewById(R.id.send_message);
gridView = (GridView) findViewById(R.id.sdcard);
gridView.setAdapter(new ImageAdapter(this));
gridView.setClickable(true);
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view, int pos,
long id)
{
// TODO Auto-generated method stub
final int position = pos;
final String path = list.get(position).toString();
final String option[] = new String[]{"Send to","Watch"};
alert.setTitle("Pick options");
alert.setItems(option, new OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
// TODO Auto-generated method stub
if(option[which].equals("Watch"))
{
if(path.contains(".jpg"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(list.get(position))), "image/jpeg");
startActivity(intent);
}
else if(path.contains(".mp4"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(list.get(position))), "video/*");
startActivity(intent);
}
else
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(list.get(position))), "audio/*");
startActivity(intent);
}
}//
else
{
Intent sendMail = new Intent(GridGallery.this, SendMessage.class);
sendMail.putExtra("path", path);
startActivity(sendMail);
}
}
}).show();
}
});
send.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
// TODO Auto-generated method stub
String path = null;
Intent sendToMail = new Intent(GridGallery.this, SendMessage.class);
sendToMail.putExtra("path", path);
startActivity(sendToMail);
}
});
}
/**
* Adapter for our image files.
*/
private class ImageAdapter extends BaseAdapter
{
private final Context context;
Bitmap bitmap;
public ImageAdapter(Context localContext) {
context = localContext;
}
public int getCount()
{
return list.size();
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView picturesView;
View myView = convertView;
if (convertView == null)
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);//getLayoutInflater();
myView = layoutInflater.inflate(R.layout.image_selection, null);
picturesView = new ImageView(context);
picturesView = (ImageView)myView.findViewById(R.id.item_grid);
picturesView.setClickable(true);
if(list.get(position).contains(".jpg"))
{
bitmap = BitmapFactory.decodeFile(list.get(position));
}
else if(list.get(position).contains(".mp4"))
{
bitmap = ThumbnailUtils.createVideoThumbnail(list.get(position), 0);
}
else
{
}
picturesView.setImageBitmap(bitmap);
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(8, 8, 8, 8);
return myView;
}
else
{
myView = convertView;
return myView;
}
}
}
}
MY problem is I can not be able to click the image or video thumbnail. also how do I able to get the image when I checked the check box.
here is XML code for Image_selection:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center_horizontal">
<ImageView android:id="#+id/item_grid" android:layout_width="100dip" android:layout_height="100dip"/>
<CheckBox android:id="#+id/check" android:layout_width="wrap_content" android:layout_height="wrap_content" />
and grid_gallery.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sdcard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</RelativeLayout>
please help me. Thanks in advance
it seems you store the image path in the ArrayList list. If so, then set an onItemClickListeber for the GridView. in the onItemClick method you get the position of the gridview which was clicked. try 'list.get(position)in theonItemClick` to get the path