ImageView and swapping images - android

I want to create simply application where user can review some pictures. In list I have some pictures and I want to show next pictures after click button. So this is the way: user start application and after click on the button, previous picture is replaced by next picture from the list. I want to use ImageView to show pictures. Can anyone help me?
I tried:
ImageView img = (ImageView)findViewById(R.id.image);
img.setImageResource(picturelist.get(pictureLeft));
where picturelist is list with pictures, and pictureLeft is int variable represents my index. To my list I add elements by:
picturelist.add(R.drawable.car);

do something like this:
yourButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v)
{
if(pictureLeft < picturelist.size())
{
img.setImageResource(picturelist.get(pictureLeft));
pictureLeft++;
}
}
});

Related

Android transform ImageView to Button programmiticaly with two images and onClickListener

I want to create a button animation with two image on an ImageView programmiticaly only and by using onClickListener. I have two image that i can set with setImageResource() fonction but i don't know how to play the button animation before the button action launches.
Please, could you explain a bit more what you are wanting? Do you want to replace the ImageButton resource when you click on it? You can achieve it setting the OnClickListener
new View.OnClickListener() {
public void onClick(View v) {
imageButtonView.setImageResource(idOfTheNewResource);
}
};
Is this what you are wanting?

Change between images with a Button

I'm new to Android and I'm trying to change the content of an ImageView with a button and if I press the button again the image changes back. I thought it would be easy with an if-else statement but I have been looking around in the ImageView API and I don't see the method that allows me to get the image that is being displayed in that moment... Any ideas?
Here is my code so far...
boton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
imagen.setImageResource(R.mipmap.imag1);
}
});
I didn't copy the rest of the code because I dont think it's necessary
You can get the image of the button with using this method:
Bitmap bitmap = ((BitmapDrawable)imagen.getDrawable()).getBitmap();
To set image of a button with another bitmap you can use:
imagen.setImageBitmap(bitmap);

android app displaying image on clicking button

Can someone help me with the code for
-if i click on button it should display a full screen image then again if i click on button on 2nd page it should do the same.
i want to know how to connect different pages/activities,when you click a button it should display some image and then again clickin on that page will display another image and so on,
images should be full screen
In your activity after setting content view use this code to start your image activity.
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(),
ImageActivity.class);
startActivity(intent);
}
});
Now put a ImageSwitcher or Image view and set a touch or click listener to change Images as per your logic.
Let's say you have two activities : MyActivity1 and My Activity2
In MyActivity1 class,create a button and on Button's click listener call MyActivity2.class using startActivity(new Intent(MyActivity1.this,MyActivity.class))
MyActivity2 class will contain one ImageView that will have its width and height as "fillparent" value in xml.
You can continue this process for as many activities you want.

hide one image and show other

I have two images(above, below) place on each other. I want to hide the part of the above image where user touchs. At the end above image will completely remove and below image completely become visible.
How will I achieve this thing in Android. I am really clueless. Please help
example:
button = (Button) findViewById(R.id.button);
leftButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v)
{
image.setVisibility(View.INVISIBLE); //to set the image as invisible
image.setVisibility(View.VISIBLE); // to set it back to visible
}
});
hope this will help you.

displaying still images in drawables on text input on android/eclipse

I'm a newbie here, sorry for the dumb question. I am trying to display an image in drawables that is equal value with the text inputted in edittext.
For example I input "A" and a certain image will appear in the next activity after I click done.
My personal idea is that, this will be done in imageview, but how about if I enter "ABC" and 3 images equal to the inputted text will appear simultaneously.
I think array will be use in this problem but I have no idea how to start.
ImageView image = (ImageView) findViewById(R.id.iamgeActivity);
image.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//my problem starts here
}
});
If I got you right..you can do it like in first activity, on clicking done button take the name of image from editText to next activity through bundle.
Intent intent= new Intent(currentactivity.this, nextactivity.class);
intent.putExtra("imagename",youreditText.getText().toString());
startActivity(intent);
In next activity take this image name from bundle and use following code to set image in your imageview dynamically:
ImageView image = (ImageView)findViewById(R.id.yourimageid);
int id = getResources().getIdentifier(imagename, "drawable", getPackageName());
image.setImageResource(id);

Categories

Resources