Android. Hide certain listview separator - android

How I can hide or delete certain listview separator? Of course I can hide all dividers
getListView().setDivider( null );
getListView().setDividerHeight(0);
but I need hide one or two dividers in my listview. for example by position. I am using custom Adapter for list data.
Thanks.

You can hide horizontal divider for disabled items of your list view (commonly used as section headers). To do this return false in areAllItemsEnabled BaseAdapter callback. Again, this only works for those views that are disabled (you return false in isEnabled callback for this item). The documentation for this callback is a little vague:
Indicates whether all the items in this adapter are enabled. If the
value returned by this method changes over time, there is no guarantee
it will take effect. If true, it means all items are selectable and
clickable (there is no separator.)
Reference.
Note that it mentions separator. I'm not sure if this is intended behavior or some kind of side effect. But it works. You can see this in ApiDemos List demo 5 (Separators).

You can either create a custom View for each ListItem where you can turn on or turn off the separator, or you can create a separator view that you add into your list view at the proper locations.

Related

Dynamically add view to android list?

Hi I have run into a design issue and can't figure out the best approach to take. Here is a sample of what I am trying to achieve:
When the user clicks on the Plus icon another row will be added below the current condition. Currently the condition row is in a listview and is setup using a custom adapter. The left col is filled with the options that the user has chosen from the select columns view. All that is working but I can't seem to figure out how to add a new row. So is there a way to dynamically add a new row to the list and fill it with the same data? OR is there a better alternate way to set this up?
So your custom adapter is starting off with three rows? Then when the user clicks on the plus icon, the onClick listener should call a method on your adapter that sets some kind of indication that there are now four rows (after which it calls notifyDataSetChanged()). And your getView() method should look at that indicator and if position == 2 (third row) and the indicator is not set, it returns an "Order By" view. If the indicator is set, then it should return a "Condition View" and only return an "Order By" view when position == 3 (fourth row). Does that make sense?
Your adapter reflects the state of your list model at any moment in time. Any event that occurs where you want to change the ListView should update some kind of state in the adapter. Then getView() should always check that current state when returning a view. So always think in two phases:
Your event (like onClick) updates some model data in the adapter somewhere.
Your adapter's getView() method always checks the current model data in the adapter to figure out how to set up the view for the given position.

View for a list of items that don't scroll, and handle on item click events by the item position

Just like a ListView but instead it doesn't scroll. Its content is added programatically via an ArrayAdapter. Is there any view that can be used for this purpose?
PS: Not LinearLayout, since it doesn't get its content from an adapter (I want the observer pattern)
Edit: Let me explain a little bit more. Suppose you need a list of items, but the list itself is not scrollable, what is scrollable is the screen.
That being said, the list of items should show ALL items, not a limited amount based on a fixed height. The way to go is LinearLayout as it is both non-scrollable and shows all items within itself.
But there is a third requierement. You don't want to add(View) directly, but instead, you want something similar to an ArrayAdapter so that you have a control of the items and their position, so you can handle on item click events based on their position. As far as I know, this can't be done using a LinearLayout. So my question is, does any view exist for this purpose?
You could try using a ListView, but disable scrolling, as described here
Put your layout inside a ScrollView and yes you have to use a Linearlayout. You need to set tag for each of your view that you add dynamically and whenever your view is clicked you can get it's position by view.getTag() and perform the required operation.
Note : Adding views at run time may affect performance.

How to Set the Focus on Selected Grid in GridView

I am implementing the Grid View in my android application.
I want the set the focus on my selected grid. How can i get the solution for this problem ?
I recommend to set a flag to each grid items which indicates selected or not.
and, when selecting grid item set the flags properly and call notifyDatasetChanged() on your adapter.
this will work. I did same.
If you need to set focus to GridView indeed, than call GridView's requestFocus() method. If you need to set focus at specified item in GridView, than find it by getChildAt() and also call requestFocus(). You also should be sure that your device isn't in Touch mode

android listview

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.

Android list with 'grayed out' items

In Android, I want to present the user with a list. When an item on the list is selected some action is performed, and this list item is no longer selectable. It is also 'grayed out' or the like to indicate that it cannot be selected the next time the list is displayed. I have seen the isSelectable() override in Adapter, but I believe this causes the item to be treated as a separator, which causes visual problems. And I have not found a way to 'gray out' an item. Any ideas? Thanks...
As far as graying out an item. I'm not sure if this is the best way, but it's what I do:
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
I'm basically making the item transparent and then setting the background color to gray. If you're reusing your list items you should also change them back to their original state if the condition is not met, i.e.:
view.setAlpha(255);
view.setBackgroundColor(Color.WHITE);
that is, if your original state was no transparency and the background color was white.
You need the view to be disabled. If you are creating the views just call .setDisabled(boolean) on the top view. Setting the list item to be disabled doesn't work very well in my experience.
Here is the solution I am using. I set up an OnItemClickListener for my ListView. When an item in the list is clicked, I take the passed in View and call setEnabled(false) on it. This will gray out the item. However, subsequent clicks on this item will still call the onItemClick method. So, you will need to check on each click if the item is enabled/disabled and act accordingly.

Categories

Resources