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;}
Related
I'm working on a GridView with setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL). By default, rows are not getting highlighted (with the blue highlight you see on WhatsApp or Gallery apps), so I am wondering, does the Android API already takes care of highlighting the selected items and I am missing something (if so, what am I missing?) or do I have to take care of highlighting selected rows by myself (if so, how to highlight, not just change the background)?
Here's my code:
gridView.setOnItemClickListener(this);
gridView.setEmptyView(view.findViewById(R.id.empty));
gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);
// multiChoiceModeListener is a subclass of AbsListView.MultiChoiceModeListener
// with no particular code on its abstracts methods.
gridView.setMultiChoiceModeListener(multiChoiceModeListener);
Use this for your ListItem background (XML layout)
android:background="?android:attr/activatedBackgroundIndicator"
It's basically only a selector, you can also build yourself: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/drawable/activated_background.xml
EDIT:
Given your comment, this solves it:
android:foreground="?android:attr/activatedBackgroundIndicator" with a FrameLayout
Also related question: How to set foreground attribute to other non FrameLayout view
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.
Here is an example of what I am saying in title. Take the app "Feedly". If there is even ONE item i your list, it looks like this:
Now, if the list is empty, there is a nice way to handle this to avoid a big, blank, white space, like so:
How can one achieve this?
Off hand I am thinking maybe this way, see my pseudo-code:
if (adapter.size < 1) {
// change ListView Background;
}
Check out the ListView#setEmptyView method.
If your have an empty ListView, the height should be 0 and it may be no use to set the background for ListView.
I have several solutions here:
Set the background for the LinearLayout/RelativeLayout, whatever which contain the ListView according to size of adapter.
Create another ImageView which is the "All read" image, and set its visibility according to data size of the ListView adapter.
Create a view for what you want to display when adapter size = 0, and use ViewSwitcher to switch between ListView and "All read" view according to adapter size. I will recommend this one since it may be more flexible for the "All read" view. You can have button, TextView, ImageView or whatever layout element you want to put in it.
2 and 3 are similar but using ViewSwitcher may make the code readability better than setting Visibility for views.
Here is an example for using ViewSwitcher.
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.
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.