I need to create a GridView full of Buttons, each labelled with text from a query.
Which Adapter should I use? A ResourceCursorAdapter, a SimpleCursorAdapater or something else?
(SimpleCursorAdpater seems like it would do the job, except I can't work out how to tell it to put the colum values as an attribute of the button, rather than the content.)
If the you're looking to handle the actual click event of the button (and not the actual parent grid item), I would just extend CursorAdapter and write your own custom CursorAdapter. Inflate your own layout containing the button, set the text, and set the click event.
Related
I want to have an expandable menu, and when you expand a child item, then it will show some custom items, items of my choice, like a text input field or a checkbox (see the image below).
Now how can I achieve that? Can I achieve that using the Eclipse GUI builder? Or do I have to create methods where the data is loaded dynamically?
UPDATE:
So I do not only want text items as child elements, but all sorts of elements, like an input field or checkbox.
This tutorial works like charm
http://myandroidsolutions.blogspot.in/2012/08/android-expandable-list-example.html
i also took code from here to make my custom expandable UI by implementing adapter
I want to create a gallery view, in which I want to select multiple images using an orange rectangular box.
It should look something like the following:
screen look like http://i.imgur.com/qAO0Q.jpg
Issues in your design:
Doing the selection by dragging the thumbs on either sides is going to be an extra headache. First of all, handling scrolling while doing selection. Secondly, handling touch/drag and deciding whether to include an item in the selection or not.
Design change:
Let me suggest a simpler way to extend your selection rectangle :
I assume the selection starts with a long click on any item. The orange selection rectangle appears over this initial item. Then a single tap on any neighboring item should include all items placed in-between the tapped and the initial item including the tapped one. That will make selection handling significantly simpler and less buggy.
Implementation:
Now this design shouldn't be too difficult to implement. Extend the Gallery widget and have members that indicate whether a selection is in progress and what is the range of selection (startIndex and endIndex) .
Override the onDraw method and draw the selection rectangle from startIndex to endIndex items.
Then you can define a custom adapter for your GalleryView, define a row XML layout file with ImageView and CheckBox and inflate this XML layout inside the custom adapter class. FYI, you will define custom adapter class by extending BaseAdapter class.
Check this example: Android custom image gallery with checkbox in grid to select multiple
What you could do:
Give ids all the images in the slide show
Use javascript to set
onclick events for the images Enable borders on the onclick event
Add to img tags
<IMG id=”1” namespace=”clicked” onclick="TriggerEvent(this)"></IMG>
Create script trigger event that changes the namespace of the selected id.
Include css to enable the borders:
.clicked{
border-style:solid;
border-width:3px;}
I have a View with a ListView appended, which actually uses a custom view item done programatically. Inside each list item I have a button which I need to track, to update another item in the view. It is only invalidated when you click on the list item button, not anywhere else in the list item.
So I thought of creating a custom Listener. I trigger it when the button is clicked, but I have no way to access it from the ListView activity.
Is there a way to simulate those setOnItem...Listener's using a custom listener? Thanks in advance
Please see this link to help with how to set onClickListener from within custom ListAdapters.
You can use the myButton.getTag() and myButton.setTag() to put and get data to/from your View/Button.
See this link as well to help with custom ListAdapters.
Here is another good example I found of how to use a custom adapter.
I have created one list view.. it is having 5 items...
Now I want split the list items...
when user clickon the first listitem or focus on first item then immediately it has to show followed some text views or other things..but it has to show same list..
and agian same when he clickon or focus on the second item that first item has to be close and second item has to act some thing....
I think you need to implement the concept of "Expandable Listview", so that the clicking on one item, it will be expanded with their sub-items.
Refer the android-sdk page of Expandable ListView: http://developer.android.com/reference/android/widget/ExpandableListView.html
For having an example, check this site: http://mylifewithandroid.blogspot.com/2008/05/expandable-lists.html
Pls, check the below image, do you want to perform as same ????
If you want to do the same, it is already given in the "API-Demos" at Views/Expandable Lists/1. Custom Adapter.
Enjoy !!
The problem is that you cannot use the standard ListView in your case, because in the standard ListView, the View of each row has to be one TextView.
In your case, you need it to be at least two TextViews (The standard Text, and the one that's gonna show up onClick/onFocus).
You have to create your custom ListAdapter, and override the getView() function.
Here is a code snippet that shows how to do it properly:
Custom Adapter
In the getView(), you have to inflate the XML file that describes your List Row, and return it.
In your case, I believe your XML file should contain 2 TextViews, one visible and one invisible.
Then, to handle the clicks, you can set a onItemClickListener on your ListView in your Activity class.
The best way may be to have your Activity class implementing onItemClickListener, and to use this onItemClickListener to handle those.
In the onClick() function, you just have to set the Visibility of your hidden TextView to VISIBLE.
You need to build custom rows, and handle showing more text on each row, there is no easy magicall way of doing it, but inflating your own rows, and setting a couple of attributes visibility isnt all that hard either.
First, I want to imitate the effect like "android.R.layout.simple_spinner_dropdown_item"
which is TextView+radiobutton
but either the getView() or getDropDownView only cares about one row at a time, while the whole radiobuttons in spinner is like one RadioGroup, and when dropdown view is opened, the radiobutton with which item is selected before must be checked.
so how can I imitate the layout like simple_spinner_dropdown_item?
Second, I want to add different ImageView in each row, so I can't just use the default simple_spinner_dropdown_item, I must redefine the ArrayAdapter.
So, is there a best way to get through these?
I like the layout in simple_spinner_dropdown_item, but I also want to add ImageView...
Please give me any clue at all
Thanks!!
extend the adapter. Override getView() and change the view that is returned to what you are after.
Cheers,
if you want to implement a more generic adapter without overriding the arrayadapter you can look at the post at http://blog.app-solut.com/2011/03/using-custom-layouts-for-spinner-or-listview-entries-in-android/ its using the baseadapter which can be modified as desired.