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);
Related
I want to know how I could change a buttons backgroundresource that mimics another button's background resource so that whenever I change that button's backgroundresource it another button mimics the looks of the first button...
for example:
int icon = R.drawable.ic_icon; //more specifically I stored R.drawable.ic_icon in SQL and retrieve and save in int icon when retrieve from that table, so when the table is change the first button dynamically change on create;
btn_01.setBackgroundResource(icon); //when this button is pressed it inflates a layout containing btn_02
btn_02.setBackgrounResource(??????); //this button is on a different layout and is used by different activity and should take the backgroundresource of the button that have been pressed to call that layout.
I could use if else statement but I have different button to be copied by the second button and each button has different backgroundresource possibility.
I couldn't understand your question fully but anyways here is what I got
You can put the resource id in the Intent before starting the activity when Btn_01 is clicked.
Btn_01.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(this,Activity2.class);
intent.putExtra("resource_key", R.drawable.ic_heart);
startActivity(intent);
}
});
then in your Activity2 you can just get your resource data and set to whatever button you want
int DEFAULT_RESOURCE = R.drawable.ic_close;
int resourceId = getIntent().getIntExtra("resource_key",DEFAULT_RESOURCE);
Btn_02.setBackgroundResource(resourceId);
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);
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.
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++;
}
}
});
Im trying to attach a picture with and Intent.putExtra, but im not really sure how to display the image when i send it to the next activity.
here is my onClick:
lv.setOnItemClickListener (new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, bring up Mockactivity.class
if(position == 1)
{
Intent myIntent = new Intent(view.getContext(), mockactivity.class);
myIntent.putExtra("myDrawable", R.drawable.mydrawable);
startActivityForResult(myIntent, 0);
}
It will click, and bring up a blank activity that i have named "mockactivity.class" if i take out the "myIntent.putExtra" line, but when that is there it does nothing.
Anyone know how to display that drawable in the next activity that im clicking in to?
Everything in the R class is an integer representing the actual resource.
In the other Activity you need to use something like...
int myDrawableId = getIntent().getIntExtra("myDrawable", -1);
In this case -1 is a default value that will be returned if the Intent doesn't contain an int extra with that name so test myDrawableId to see if it is -1 before trying to use it.
You should then be able to use myDrawableId in the same way as you would use R.drawable.mydrawable.
EDIT: Using this code...
ImageView view = (ImageView) findViewById(...);
...you are trying to find the ImageView and not the drawable that is used for its image source. You should be using...
ImageView view = (ImageView) findViewById(R.id.myImageView);
...where myImageView is the id of the ImageView in your mockactivity.xml layout file. If you do that correctly then simply do the following to set the image...
view.setImageResource(myDrawableId);