today i need help from you!
I have a recyclerview with some data(get from json), with adapter.
I have some button(with id) with a drawable left, and onclick on the button i execute this for the clicked button :
Drawable image = ContextCompat.getDrawable(context, R.drawable.active);
image.setBounds(0, 0, 70, 70);
Button.setCompoundDrawables(image, null, null, null);
I Change the drawable with a new drawable.
My question is now.
When i click on some button in the list, and i scroll, the button return to default drawable... WHY?
Thanks every one for help!
Resolve with movies.add(new Costructor("","","","","","",""));
When you scroll RecyclerView then all data reset with Adapter's data.
When you click and change Drawable with R.drawable.active, It will change only in screen for temporary.
Please update Adapter's data.
Related
Hii all I am not good at designing. I need help with the following layout.
1-How to add the images right next to pay(Subscription) , like we add badge?
2-How to set the view , like it is when we select an item in the image below? Showing a light blue marker at the start of it.
3-How to add the bottom blue footer line?
P.s. My navigation view is also very slow. Any tips on that would be helpful too.
While Initializing my navigation drawer , I did this.
gallery=(TextView) MenuItemCompat.getActionView(navigationView.getMenu().
findItem(R.id.menu__pay_subscription));
initializeCountDrawer();
Then The method.
private void initializeCountDrawer(){
gallery.setGravity(Gravity.CENTER_VERTICAL);
gallery.setTypeface(null, Typeface.BOLD);
gallery.setTextColor(getResources().getColor(R.color.colorAccent));
Drawable img = context.getResources().getDrawable( R.drawable.cards);
img.setBounds( 0, 0, 200, 40 );
gallery.setCompoundDrawables( img, null, null, null);
}
I want to set the opacity of each and every Listview row using android:alpha. I tried doing so but the row doesn't get the transparent background. I have a colorful background of the layout and I want a glass or transparent type of row of the ListView. How can I do it?. I don;t want to use any adapters for this. So please suggest some simple methods.
View backgroundimage = findViewById(R.id.background);
Drawable background = backgroundimage.getBackground();
background.setAlpha(80);
If you are set opacity of listView us below Code
android:background="#80ColorCode"
I created a custom listview for installed apps. The listview contains icon and text. Now my problem is how to get/retrieve the BitmapDrawable icon from the customised listview when onListItemClick?
The icons in the custom listview is from:
static ArrayList<BitmapDrawable> Iconlist= new ArrayList<BitmapDrawable>();.
Inside onListItemClick I used:
SelectedIcon=(BitmapDrawable) Iconlist.get(position);
to get the icon, but its not working.
Please help me.
As #Rakesh Bhalani says, you should use the view returned by onListItemClick as argument, casting the view for an ImageView:
ImageView imageView = (ImageView)view.findViewById(id_of_your_icon);
then extract the drawable from the ImageView, casting as BitmapDrawable:
BitmapDrawable drawable = (BitmapDrawable)imageView.getDrawable();
In onItemClick listener of ListView you will get clicked 'view' as an argument, you should use view.findViewById(id_of_your_icon) to get the icon.
I have a row in a listview activity where an image should be changed when the row is selected. The new image is identical but larger (double size) than the original image. It is supposed to be reduced when it is deselected (Selection is implemented using my internal selection, not the android keyboard selection kind) again.
Problem is when (selected) I change the picture (at the time of bind) of my ImageView () using setImageResource() it does not update to the new larger version in my List row on the first click. Second execution of bind works fine. The same applies for the old item being deselected. The change to a smaller icon does not get in effect until a second click. The problem repeats itself each time I select another row than the currently selected and starts working correctly again on the second click.
I have stepped through code and seen that I pass the right id to the ImageView and this is prooved by the fact that another View showing a yellow border on the same row is changed to visible/hidden when selected/deselected.
To me it feels like the setImageResource() does not refresh the view immediately, but using invalidate() on the view or the row has no effect at all.
Is this a bug (how to work around) or do I do something wrong?
Code: (from my holder class using the holder pattern - executed by the adapter bind method)
#Override
public void refreshFromCursor(final Context context, final Cursor cursor) {
...
boolean selected = adapter.getSelectedPosition()==cursor.getPosition();
if (selected){
selectedIndicator.setVisibility(View.VISIBLE); // Show a "selected" yellow border indicator to the left
} else {
selectedIndicator.setVisibility(View.GONE); // Hide a "selected" yellow border indicator to the left
}
...
if (selected) completionResId = R.drawable.folder_selected;
else completionResId = R.drawable.folder;
...
statusIcon.setImageResource(completionResId); // !!!!! This is where I set the image that does not refresh/resize
...
}
Also tested exchanging the
statusIcon.setImageResource(completionResId);
with
statusIcon.setImageDrawable(context.getResources().getDrawable(completionResId));
but nothing changes in the problematic behaviour
In my opinion it is about the way you have implemented,
if you provide us the full code of refreshFromCursor(...) function we can have better understanding of what you did.
I found a hack. just make your drawable bigger
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="500dp"
android:height="500dp"
android:viewportWidth="139"
android:viewportHeight="139">
<path
android:fillColor="#000000"
android:pathData="M117.037,61.441L36.333,14.846c..." />
</vector>
here I set the drawable to be drawn on a 500dp canvas (instead of a 139dp one that was there originally) and it did the trick. no more weird tiny icons that later increase in size.
I have to show list view as like below image
Here I have the view in the xml as like this
<View
android:id="#id/margin"
android:background="#6DAAE9"
android:layout_width="20.0dip"
android:layout_height="fill_parent" />
I Have to change this background (#6DAAE9) dynamically when list is loaded and I have to fix these colors to corresponding item even the list items are increased.
Can any body help me. Thanks in advance
Basiclly you need to edit your getView method.
you can use
convertView.setBackgroundColor(Color.parseColor("#6DAAE9"));
With your appropriate logic, meaning if you want it to be random set random color or hold an array with the order, etc.
See this listview I added list item as per odd or even row and you can do it checking position in getView() method.And you should put imageview for that and set color rather that set color to row.
if(position==0){
//here set color for imageview which position is 0
}else if(position==1){
//here set color for imageview which position is 1
}
....