i want to increase my integer. but i don't know to fix it
Even i am using this code, my picture more brightness with int +10 from before.
try {
ImageView image = (ImageView) findViewById(R.id.imgView);
Bitmap bMap = mPhoto;
int a=0;
image.setImageBitmap(SetBrightness(bMap,20+a));
a = a + 10;
} catch (Exception e) { }
Can you help me?
solution
try {
ImageView image = (ImageView) findViewById(R.id.imgView);
Bitmap bMap = mPhoto;
mPhoto = Bitmap.createBitmap(SetBrightness(bMap,20));
image.setImageBitmap(mPhoto);
} catch (Exception e) { }
Just with code above....
When i click, this code increase by itself :)
please notice that your variable a should be a global variable. so that it doesn't set to zero every time when you try to increase brightness.
And for the way you can increase brightness by value 10, on clicking a button is:
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
//your code//
a = a + 10;
}
in your button in click set this
a += 10;
You can set onClickListener for imageView. And in onClick method you can increase your integer value.
imageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
//increase integer value
a = a + 10;
}
Related
I have three Images. When I first touch, first Image is shown, when I second touch, second Image is shown, and then when I third touch, third Image is shown. After all, when I fourth touch, I want to show first Image return and so on.
Can someone point me to show how handling or touching on a ImageView of android?
The below should do what you need:
public class MainActivity extends Activity {
ImageView image;
int i=1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
image = (ImageView) findViewById(R.id.imageViewName);
setButtonOnClickListeners();
}
}
image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (i==1){
image.setImageResource(R.drawable.image1);
i++;
}
else if(i==2){
image.setImageResource(R.drawable.image2);
i++;
}
else if(i==3){
image.setImageResource(R.drawable.image3);
i++;
}
else if(i==4){
image.setImageResource(R.drawable.image4);
i=1;
}
}
});
I've not tested but the idea is correct. When you click the image it will change the drawable depending on the value of i. When you get image 1 i will equal 1. Onclick will increment i until i==4 which it will reset to 1 as you requested.
A while loop might be tidier but this was the quickest soultion I thought of.
how to handle click on an ImageView
You can simply set a View.OnClickListener for your ImageView:
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// do stuff
}
});
Code that is not working
public void fade(View v){
ImageView pic1 = (ImageView) findViewById(R.id.pic1);
ImageView pic2 = (ImageView) findViewById(R.id.pic2);
pic1.animate().alpha(0f).setDuration(2000);
pic2.animate().alpha(1f).setDuration(2000);
}
Not quite sure what you are asking for, but if you want to change the image back and forth onClick, you could try modifying the code I wrote below.
// set a boolean value
private boolean firstImageShown = true;
public void clickFunction(View view) {
ImageView firstImage = (ImageView) findViewById(R.id.firstImage);
if ((firstImage != null) && (firstImageShown)) {
firstImage.setImageResource(R.drawable.sample_image2);
firstImageShown = false;
} else {
if (firstImage != null) firstImage.setImageResource(R.drawable.sample_image1);
firstImageShown = true;
}
}
//Suppose you have two images rose_1 and rose_2 and you want to switch back
//and forth between these on a button press.
//Set a static variable
private static int switcherPressedCount = 2;
//Map the onClick attribute of the button to a function say "switcherPressed".
//"imageView1" is the id attribute of the image which first gets loaded in the
//app, in this example, it is the attribute of rose_1.
public void switcherPressed(View view){
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
if(switcherPressedCount%2 == 0) {
imageView.setImageResource(R.drawable.rose_2);
switcherPressedCount = 3; //to avoid reaching maximum int limit.
}
else {
imageView.setImageResource(R.drawable.rose_1);
switcherPressedCount = 2; //to avoid reaching maximum int limit.
}
}
public class Serchresult extends Activity implements OnClickListener {
ImageView imageView1;
String Status;
String Reason;
TextView status;
TextView reason;
ImageView statusicon;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.act_serchresult);
Intent intent = getIntent();
Status = intent.getExtras().getString("Status");
Reason = intent.getExtras().getString("Reason");
imageView1 = (ImageView) findViewById(R.id.searchstatus_imgBack);
imageView1.setOnClickListener(this);
status = (TextView) findViewById(R.id.status);
reason = (TextView) findViewById(R.id.reason);
statusicon = (ImageView) findViewById(R.id.imageView1);
reason.setText(Reason.replace("null", ""));
if (reason.equals("ACCEPTED")) {
AQuery aq = new AQuery(getApplicationContext());
statusicon.setImageResource(R.drawable.accept_icon);
} else if (reason.equals("REJECTED")) {
AQuery aq = new AQuery(getApplicationContext());
statusicon.setImageResource(R.drawable.reject_icon);
}
else {
// reason.setCompoundDrawables(null, null, null, null);
statusicon.setImageResource(0);
}
status.setText(Status.replace("null", ""));
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.searchstatus_imgBack) {
finish();
}
}
}
here is my code i want display image from drawable folder accept and reject icon .i am getting ACCEPTED and REJECTED from intent on the basis of this response i want to display image in image view i have apply condition but image is not visible please help me where am doing wrong
Your code seems working. But still you can try following code to display image. Make sure your if-else conditions are working
Bitmap defBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.accept_icon);
statusicon.setImageBitmap(defBitmap);
Maybe the Bitmap is too big for the heap, try use BitmapFactory.Options to reduce the size.
BitmapFactory.Options op = new BitmapFactory.Options();
op.inSampleSize = 4;
statusicon.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.accept_icon, op));
I want to create 600 imageview at runtime and add it to linear layout at runtime.It cause block my user interface. My activity appear when all imageview created and added to linear layout. How to resolve this.
Please help for this.
for(int index = 0; index < ProductItemArray.Image_URL.length; index++)
{
ImageView bottomImageView = new ImageView(context);
bottomImageView.setTag(index);
if(Helper.isTablet(context))
bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(100, context), VirtualMirrorActivity.convertDpToPixel(100, context)));
else
bottomImageView.setLayoutParams(new Gallery.LayoutParams(VirtualMirrorActivity.convertDpToPixel(80, context), VirtualMirrorActivity.convertDpToPixel(80, context)));
UrlImageViewHelper.setUrlDrawable(bottomImageView, ProductItemArray.Image_URL[index]);
bottomImageView.setBackgroundResource(R.layout.border);
linearLayout3.addView(bottomImageView);
bottomImageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
final int position = (Integer) v.getTag();
linearLayout.removeAllViews();
Thread newThread = new Thread(new Runnable() {
public void run() {
isAlreadyExistInWishlist = true;
URL url_1 = null;
try {
VMProductListPaging.productUrl = ProductItemArray.Image_small_URL[position];
VMProductListPaging.productId = ProductItemArray.productId[position];
VMProductListPaging.productName = ProductItemArray.product_Name[position];
url_1 = new URL(ProductItemArray.Image_small_URL[position]);
bmp = BitmapFactory.decodeStream(url_1.openConnection().getInputStream());
isExecuted = true;
bitmapModelsHandler.sendMessage(bitmapModelsHandler.obtainMessage());
}
catch (Exception e) {
//Toast.makeText(context,"Sorry!! This link appears to be broken",Toast.LENGTH_LONG).show();
}
}
});
newThread.start();
}
});
}
Having 600 images in memory in the same time is probably not a good idea.
You should consider using some lazy loading via an adapter (with a ListView, a Gallery, a GridView, a Spinner,etc...) which will manage recycling/releasing of views.
I am developing application on Images.
In that if I click on same image the image will replace by another one that already into my Drawable
Right now onclick I am able to display only Toast Message; but I want to replace Image. I don't know How to do?
Any Help and suggestion appreciable.
you can take it images name as : img1 ,img2 ,img3.
ImageView imgV = (ImageView) layout.findViewById(R.id.img1);
imgV.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (v.isClickable()) {
i++;
String ii = new Integer(i).toString();
Log.i("Inside", ii);
if (ii.equals("3")) {
Toast.makeText(getApplicationContext(), "Call another Image ",Toast.LENGTH_SHORT).show();}
ImageView imgV = (ImageView) layout.findViewById(R.id.img1);
imgV.setClickable(true);
int counter = 0;
imgV.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
i++;
if(i == 3){
imgV.setImageResource(R.drawable.img2);
//Or you may want to use
//imgV.setBackgroundResource(R.drawable.img2);
i = 0;
}
}