Android gallery problems - java

i have a gallery, and over i have a text view if i click in an image it shows a text but i wanna when i scroll the gallery the text view shows a text too, for example if i scroll and the gallery image is a tree, the text view must show tree, i already have the event:
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,long id) {
Toast.makeText(MainActivity.this, "" + position,
Toast.LENGTH_SHORT).show();
}
});
I'm looking for another without having to click the text show me

Related

saving RecyclerView images state when scrolling

I'm using Picasso in onBindViewHolder but when scrolling up or down it reload same images urls from internet this make the list so bad and slow
so i want when it first load save the scroll state for images and do not load it again '
how i can do that?
onBindViewHolder Method :
#Override
public void onBindViewHolder(MyCustomAdapter.CustomViewHolder holder, int position) {
Dishes di = dish.get(position);
//Download image using picasso library
Picasso.with(mContext).load(di.getDishImageUrl())
.error(R.drawable.ic_error)
.placeholder(R.drawable.fav_btn)
.into(holder.imageView);
//Setting text view title
holder.textView.setText(Html.fromHtml(di.getDishName()));
View.OnClickListener clickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
CustomViewHolder holder = (CustomViewHolder) view.getTag();
int position = holder.getPosition();
Dishes di = dish.get(position);
Toast.makeText(mContext, di.getDishName(), Toast.LENGTH_SHORT).show();
}
};
//Handle click event on both title and image click
holder.textView.setOnClickListener(clickListener);
holder.imageView.setOnClickListener(clickListener);
holder.textView.setTag(dish.get(position));
holder.imageView.setTag(dish.get(position));
}

listview item click event not working in android

I have a ListViewin my ListView show ImageButton, ImageView, Button, TextView
I set ListView.OnItemClickListner. When I run my project, it shows my ListView.
But when i click on listview it's not working
what is wrong? and I want button, ImageButon,ImageView click events should call Activity or dialog ? Help me?
This is the code:
list.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
Toast.makeText(getActivity(), "sdadad",1).show();
}
});
Add one tag in parent layout of your custom layout
android:descendantFocusability="blocksDescendants"

How to use setVisibility on integer array in adapter list view by onclick on ImageView in android

I'm trying to invisible an image when it is clicked by storing images from drawable into integer array using adapter list view, but I'm unable to get it. This is the code I'm using:
When i click on an image it should get invisible.I am storing images in int array and applying setVisibilty invisible but its not working.i want an image to be displayed in centre of screen and the one which is clicked should get invisible.i am trying to store images in an integer array and setting it up in adapter list.i am calling this function
imageIDs[position].setVisible(false);
Integer[] imageIDs = {
R.drawable.c2,
R.drawable.c3,
R.drawable.c4,
R.drawable.c5,
R.drawable.c6,
R.drawable.c7,
R.drawable.c8
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Note that Gallery view is deprecated in Android 4.1---
Gallery gallery = (Gallery) findViewById(R.id.gallery1);
//Adapter list
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
//onclick event
public void onItemClick(AdapterView<?> parent, View v, int position,long id)
{//displaying image clicked i am trying to invisible this pic when click
Toast.makeText(getBaseContext(),"pic" + (position + 1) + " selected",//dispplpaying msg
Toast.LENGTH_SHORT).show();
//imageIDs[position].setVisible(false);
// display the images selected
ImageView imageView = (ImageView) findViewById(R.id.image1);
imageView.setImageResource(imageIDs[position]);
//setting image on screen from using xml
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context context;
private int itemBackground;
public ImageAdapter(Context c)
{
context = c;
// sets a grey background; wraps around the images
TypedArray a =obtainStyledAttributes(R.styleable.MyGallery);
itemBackground = a.getResourceId(R.styleable.MyGallery_android_galleryItemBackground, 0);
a.recycle();
}
// returns the number of images
public int getCount() {
return imageIDs.length;
}
// returns the ID of an item
public Object getItem(int position) {
return position;
}
// returns the ID of an item
public long getItemId(int position) {
return position;
}
// returns an ImageView view
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
//imageIDs[position].setVisible(false);
//i am trying it here but its not working
imageView.setImageResource(imageIDs[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
imageView.setBackgroundResource(itemBackground);
return imageView;
}
}
}
I'm assuming you're trying to use this code:
//imageIDs[position].setVisible(false);
If so then what you're doing is calling setVisible on an Integer, which does not have that method. What you need to do is get a reference to the ImageView in which the image is being displayed and then call setVisibility(View.INVISIBLE) or setVisibility(View.GONE) on it.
Also it seems like you're trying to set the image to invisible but then you go and put the same resource back into the ImageView so I'm not sure what you're trying to do there.

android: how to select other view in onItemClick

I try to create an Android tic-tac-toe application which I use grid view as an arena. This is the game rule:
The arena is 3x3 scale that mean 9 box.
When I click a box, the cpu player select the other box.
The box that have clicked will change its image.
The problem is I only can change my selected view, and I want the CPU player to change his selected view. That mean on one call of onItemClick, there must be two views involved and changed its image. How can I do this? Can I change CPU ImageView based on position?
This is my code:
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
// my selected view
ImageView myBox = (ImageView) view;
myBox.setImageResource(R.drawable.mybox_img_after_clicked);
//cpu selected view
//ImageView cpuBox = ???;
//cpuBox.setImageResource(R.drawable.cpubox_img_after_clicked);
}

Changing an image in a dialog box before showing it

I have an activity which consists of a GridView with multiple (different) images. When the user clicks on one image, a customized dialog box shows up in which an enlarged version of the image appears as well as some text below.
What I want accomplished: the image shown in the dialog box must correspond to the chosen image in the GridView. I thought that I could change the image resource in the onItemClick method, but the application crashes instead (only when I use the setImageResource command).
Here is the code:
public class Releases extends OptionsActivity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.releases);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ReleasesImgAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
//Toast.makeText(Releases.this, "" + position, Toast.LENGTH_SHORT).show();
if (position == 0)
{
CustomizeDialog cdWCE = new CustomizeDialog(Releases.this, R.layout.releases_popup);
ImageView wce = (ImageView)findViewById(R.id.rlsImg);
wce.setImageResource(R.drawable.image2);
cdWCE.show();
}
}
});
}
}
releases.xml simply consists of a GridView.
I can't debug the program because my Eclipse debugging haven't been working for a while now.
Try finding the ImageView in the actual dialog where you set the layout (e.g.
ImageView wce = (ImageView)cdWCE.findViewById(R.id.rlsImg);

Categories