I am trying to get a Imageview from textview. I tried many methods but not able to set that textview on Imageview as image.
I tried following method:
TextView tv = (TextView)findViewById(R.id.textview);
tv.buildDrawingCache();
ImageView img = (ImageView)findViewById(R.id.imageview);
img.setImageBitmap(tv.getDrawingCache());
but i am not still able to show that textview on Imageview. Can someone help me that how can i set textview as image on that imageview?
Try this, if it maya help you
yourTextView.setDrawingCacheEnabled(true);
yourTextView.buildDrawingCache();
yourImageview.setImageBitmap(tv1.getDrawingCache());
call
tv.buildDrawingCache(true);
Bitmap b = tv.getDrawingCache(true).copy(Bitmap.Config.ARGB_8888, false);
tv.destroyDrawingCache();
img.setImageBitmap(b);
Related
Let's say I have 4 images:
ImageView a = (ImageView) findViewById(R.id.a);
ImageView b = (ImageView) findViewById(R.id.b);
ImageView c = (ImageView) findViewById(R.id.c);
ImageView d = (ImageView) findViewById(R.id.d);
And then I set the visibility of those images by this:
a.setVisibility(View.INVISIBLE);
b.setVisibility(View.INVISIBLE);
c.setVisibility(View.INVISIBLE);
d.setVisibility(View.INVISIBLE);
Is there anyway I can group those 4 images and then set the visibility to that group of images?
Something like this:
images[] = {a,b,c,d};
images.setVisibility(View.INVISIBLE);
Thank you.
If you don't want to use a ViewGroup your basic idea is good. I use it often. Just do
ImageView images[] = {a,b,c,d};
for (ImageView view : images) {
view.setVisibility(View.INVISIBLE);
}
The usual approach would be to have all the views in the same ViewGroup i.e. a layout and then set the visibility of the group in order to apply it to all children. But this really depends on how the views are laid out in the first place.
You can put all those images in layout and then control visibility of that layout.
I implemented lazy ListView adapter to display the images along with text from internet in Listview.Now I want to get the Bitmap of image when particular ListItem clicked and want to display it in a ImageView,But I am unable to get the Bitmap from the image.I am using this logic in OnItemClickListener for ListView:-
View imageView1 = listView1.getChildAt(position);
ImageView imageView3 = (ImageView) imageView1.findViewById(R.id.image);
Bitmap b;
imageView3.setDrawingCacheEnabled(true);
imageView3.buildDrawingCache();
b = ((BitmapDrawable) imageView3.getDrawable()).getBitmap();
car_image_detail.setImageBitmap(b);
But getting NullPointerException sometimes.Can anyone please help me out..?
Please use my code. I am getting the image from the listview when a particular item is clicked and setting it to another imageview.
//Code in listview itemclick listener
final ImageView imageView = (ImageView) view.findViewById(R.id.icon);
final BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable();
final Bitmap yourBitmap = bitmapDrawable.getBitmap();
show.setImageBitmap(yourBitmap); // show is another imageview
I have a image view and a text view.The text view is coming below image view.I need the textview to the right of image view.How to do it?
LinearLayout ThelayoutL = new LinearLayout(getApplicationContext());
ThelayoutL.setOrientation(LinearLayout.VERTICAL);
ImageView TheItemImageL = new ImageView(mContextL);
TheItemImageL.setImageBitmap(ItemImageBytesListG.get(PositionP));
TheItemImageL.setScaleType(ImageView.ScaleType.FIT_XY);
TheItemImageL.setLayoutParams(new ListView.LayoutParams(100, 100));
TextView tvItemNameL = new TextView(mContextL);
tvItemNameL.setText(zItemNameListG.get(PositionP));
tvItemNameL.setGravity(Gravity.CENTER);
tvItemNameL.setTextSize(10);
tvItemNameL.setTextColor(Color.parseColor("#000000"));
try ThelayoutL.setOrientation(LinearLayout.HORIZONTAL);
Replace
ThelayoutL.setOrientation(LinearLayout.VERTICAL);
to
ThelayoutL.setOrientation(LinearLayout.HORIZONTAL);
hope it helps.
i have a ImageView in the layout, when i click on the image i want to get that image into a variable and replace with another image in this ImageView. please help me..
The onClick Listener will give you a View, that's the ImageView that was clicked. Cast it to an ImageView and do whatever you want with it.
in this example i have take previous image in Drawable and replace i with new image. if you set any imageview to image which stay in drawable variable(d) then use :: setBackgroundDrawable(d); is useful
public void onClick(View v){
ImageView i;
i = (ImageView) findViewById(R.id.img);
Drawable d = i.getBackground();
i.setBackgroundResource(R.id.secondImage);
}
I need to show a image, when i press a button on my application.
I'm trying with:
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageDrawable(R.drawable.loading);
but it shows an error.
Anyone can help me? Thanks.
import package_name.R.drawable;
ImageView imageView = (ImageView) findViewById(R.id.imageView2);
imageView.setImageResource(drawable.loading);
OR
you can set the image from the start, set it to invisible and when you want to show it just change the visibility property.
for future visitors:
sometime setImageDrawable(Drawable) method show an error like:
The method setImageDrawable(Drawable) in the type ImageView is not applicable for the arguments (int)
can try following codes:
ImageView imageView = (ImageView) findViewById(R.id.myImageView);
Drawable image = getResources().getDrawable(R.drawable.your_image);
imageView.setImageDrawable(image);
--------- OR can try this ------------------
imageView.setImageDrawable(ContextCompat.getDrawable(YourActivity.this, R.drawable.your_image));
hope it work for you.