Is it possible to add separator view to listview without changing adapter's list of items?
I know that you can inflate different types of items with different layouts but that's not what i'm looking for. I dont want to change list of items which adapter uses. Only want to add separator at desired position.
Something similar to ListView#AddHeader. It adds view at the top of the list but doesn't change list of items.
I want to add view between two items, but don't want to change list of items.
Is this what you're looking for? dividerHeight property.
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:dividerHeight="2dp" >
Related
When I scroll the list, fastscroll thumb is showed but the scrollbar thumb and track not showed.
Here is my XML code:
<ListView
android:id="#+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarTrackVertical="#drawable/bg_scroll"
android:scrollbarThumbVertical="#drawable/scroll_bar"
android:divider="#drawable/list_line"
android:fastScrollEnabled="true"`/>
My fastscroll thumb drawable is setted in styles.xml AppTheme.
Since you have set android:fastScrollEnabled="true" you need to set the fastScroll properties like android:fastScrollTrackDrawable="#drawable/"and 'android:fastScrollThumbDrawable="#drawable/". And also consider what #Gouse Mohiddin has said. You need to have enough rows inside to make it scrollable.
Please check the data you passed to list view because fast scroll is only displayed when you have more list items to scroll.
Make sure you have these lines in recycler view tag
app:fastScrollHorizontalThumbDrawable="#drawable/thumb_drawable"
app:fastScrollHorizontalTrackDrawable="#drawable/line_drawable"
app:fastScrollVerticalThumbDrawable="#drawable/thumb_drawable"
app:fastScrollVerticalTrackDrawable="#drawable/line_drawable">
I have a row.xml file which define a row whose content and number of rows will be dynamic.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/room_detail_row_in_hotel_detail">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/name"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/sz_blue"
android:id="#+id/price"/>
</LinearLayout>
The best solution as suggested by #Hell is to use a Listview.
Say you are operating within a fragment, add a listview in the xml for the same.
The fragment (or activity) containing the listview will dynamically create list(preferrable)/array of data.
In your case the dataset will essentially either be a list of class object which uniquely have two objects, price and name.
Create an adapter, could be a BaseAdapter or any other form depending on your specific use-case. This adapter would essentially inflate your row layout (as specified in your question) and dynamically add the data.
Add the data into the adapter using it's constructor. Following which assign this adapter as the listview's adapter and call the "notify" method for the adapter indicating that a new dataset has been loaded and the list needs to be refreshed.
Also note, it's highly suggestible to add smoothScroll to your listview for obvious reasons.
I guess what you are looking for is a RecyclerView.
You should use the Viewholder-Pattern to reuse your layouts
I'm trying to change the items color on the list view.
I tried that , but its not working:
android:textColor = "#FFFFFF"
<ListView
android:id="#+id/listViewToDo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="false"
android:textColor="#FFFFFF" >
</ListView>
To change listView items color, you should implement a custom adapter and pass it a view.
We can change the view attributes programmatically from the getView() methods which returns a View object.
To create a listView you'll need one xml file to represent a row, right?
So, if you want the same color for all of the rows, you could just set android:textColor="#FFFFFF" there.
Hope it helps.
I have a simple application which basically consists of a line of buttons and a ListView of items to be selected and manipulated. There might be only one item in the list or a few. However, I would prefer if the list would populate from the bottom of the ListView, since the way most people hold their phones makes it easier to select items closer to the bottom of the screen. Is this possible?
You can have the ListView stack its items from the bottom up using a simple XML property
under the xml -
<ListView
android:stackFromBottom="true"
...
></ListView>
Please read #The Berga answer to otherwise this won't work.
Joe answer is correct but it's important to point out that it only works if the ListView's width and height are set to match_parent or fill_parent.
If set to wrap_content it still will populate from top to bottom.
I tried android:stackFromBottom="true" with android:layout_width="match_parent"
android:layout_height="fill_parent" but it didn't work
finally
Adapter.insert(post,0);
saved my day. Here post is the class which is returning data to be added
These are a must tags for the reverse populating of the list view.
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stackFromBottom="true"
</ListView>
I have a ListView that with alphabetical headers for each letter. I also have an index function that brings the letter headers to the top of the screen.
My problem is when I reach the end of the list setSelection is unable to bring the last few headers to the top because it will not scroll past the end of the list.
My question is this: Is there a way to add a blank space to the end of the screen dependent on screen size? I would like to scroll until the last item in the list is at the top of the listView.
The easiest way to add space is to add padding in xml and set clipToPadding:"false".
For RecyclerView
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:clipToPadding="false"/>
For ListView
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:clipToPadding="false"/>
And same goes for the ScrollView
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:clipToPadding="false"/>
This specifically adds the blank space to top and bottom but hide the space when you scroll the view.
Try the followings:
View footer = new View(getActivity());
footer.setLayoutParams( new AbsListView.LayoutParams( LayoutParams.FILL_PARENT, 100 ));
mListView.addFooterView(footer, null, false);
I'm assuming you are using an extension of BaseAdapter to populate your ListView?
There may be a built-in way to do what you are asking, but I don't know of one. If you end up creating it yourself, how about this approach:
Return list.size() + EXTRA in getCount()
Modify getItem() to return something sane if it asks for an item not in your list
Modify getView() to configure the given view as a simple horizontal padding with the same height as the rest of your views if the position index is more than your list size
You would need to fiddle around with the EXTRA constant to see what value is best.