The first button in a gridView of buttons is not changing colour - android

I am unable to get the first button in a gridView to change colour. The button works fine, and it operates as normal when it is clickd but it wont update the colour of the first button. I am using a custom list adapter to generate the gridView. This only seems to happen if I want to change it in real time, if i load the buttons at a later stage the buttons do change colour. I've tried to hard code it for the first button in the list but that doesn't seem to work either.

In Grid view First you have to create a custom adapter for it and then in the Override method "get View()" you will get the specific cell and then change its background color.
For Details click the link : https://developer.android.com/guide/topics/ui/layout/gridview.html

Related

How can I change radio button to contain text and look like a selectable button?

How can I get selectable view on my gridview like this
I have checked some of the suggestions on a few questions but I still am not able to make it work using Buttons. If it is possible with this I still can use it though most suggestions state that you can change the radio button but none shows how. I need mine with text or color or both according to the category. Only one view in the grid can be selected.
You may consider customising your radio button by changing the images associated with it.refer this

Android GridView selected item border/highlight

In the native Gallery app on Android, when Select item via Option Menu action, you can select multiple items, each grid item which will have a colored-border overlay on top signify as selected when clicked.
Question:
How to do this dynamically using getView() in the ImageAdapter
class? (since there is setBackgroundColor() but not setBorder()
Is there a better way to accomplish this? (such as creating a padding
of some sort for the image within the gridview cell, then set the
background color which will look like a border)
I finally decided to use the 2nd method in the original post: creating a padding for ImageView within the gridview cell and set the background color.
I used ImageView.ScaleType.CENTER_CROP with setCropToPadding(true); for the ImageView.

Android Spinner does not close after using setSelection()

I have a scenario where I want to programmatically change the value of my spinner using setSelection(). This works great, except that if the spinner is open (expanded?) an the time, the spinner does not close. Eg, the menu stays up, despite calling setSelection().
How can I programmatically close the spinner? I have tried performClick() to no avail.
edit: more details:
The reason I'm trying to do this is that my spinner actually uses a compound layout for each selection row. Namely, I have a linearlayout which contains an image, text, and button. The idea was that the button serves as an "edit" button (which opens an activity), while pressing on the image/text select the row (per usual).
The problem came when I added the button. Suddenly, the image & text no longer captured the press event to change the combo. In other words, adding a button to the row destroyed the touch-handling capacity of the entire row. So I tried to manually implement a click handler for the image/text, which subsequently executed a setSelection... which is where I ran into this problem.
You say that after adding the button you lost the click handle on the entire row. Try adding this android:descendantFocusability="blocksDescendants" to your row layout, and see if you can get the clicks to work properly.

Android Listview background image shows on each row, why?

I have a ListActivity with a ListView and everything works great; however I am trying to set a background image and the image is appearing in each row and making the row very tall.
How do I make the background for that view so the rows don't pick up the image?
In onCreate() of your ListActivity, call
getListView().setCacheColorHint(0);
getListView().setBackgroundResource(R.drawable.backgroundresource);
Without the .setCacheColorHint(0) the background will flash to the original background color every time you scroll. With it added the background is a constant. (Thanks Matt it fixed that issue for me).
maybe you are attaching the background to the list item, be sure to do this in your ListActivity:
getListView().setBackgroundResource(...)

get a small list when clicked on a button

i have a image view and on top of it i have a button. now what i want is when i click on the button i should get a list of images on same Activity.actually i am trying to make a list in button,s onClick event. event gets fired but it does not show the list. anybody can have any idea how shall i achieve this i am also making my layout programmatically.
thanks alot
Without seeing some code it's hard to give a definite answer, but these are a few possibilities.
Create the listview together with the button, but set it's visibility to View.GONE or View.INVISIBLE. In the button's onClick method, set it to View.VISIBLE.
Alternatively, do the listview creation in the button's onClick (which I gather is what you're doing?), making sure you don't forget to add it to your layout. I have no idea why this does not work for you. Show some code or use the debugger to step through it and find out where it goes wrong.

Categories

Resources