Animate the switch between not empty listview and empty listview - android

I have a listview filled with data
at some point the user can wipeout that data and reveal the emptyview that i set up.
I want the listview to vanish from the screen animated, revealing the empty data.
How do that ?

you can use the empty view. Simply add a view with #android:id/empty to your layout and when the dataset is empty it will be automatically show. For instance:
<TextView
android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent" />

Related

How to create an empty space after last element in a RecyclerView?

I am using RecyclerView from support.v7 library to display items on shopping list.
When I'm scrolling to the end of my data, I can't see the price in the right side of the last item.
I want to add some space after scrolling to the last item, so that the button don't cover it.
Here is the image of the App with RecyclerView and FAB:
I can simply add an empty object to the list for an Adapter, but in this case it will behave like the rest of rows (it will have checkbox, and price 00.00 on the right side).
Is there another way to do that?
You can add bottomPadding and disable clipping, such as:
<RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
<!-- Bottom Padding, or space below last item -->
android:paddingBottom="10dp"
<!-- Clipping diabled -->
android:clipToPadding="false" />

Android listview inside viewpager not swiping

I have a listview inside of a viewpager. I set an empty view on the listview. If this listview starts empty, when i add something to it then right or left swipes on the listview won't switch between tabs. If the listview starts with something (not empty) when i set the adapter on it, then i can swipe. If i remove the setEmptyView on the listview, it always works whether it starts with data or without it.
How can i set an empty view and still get the listview to swipe between tabs?
This is how i set the empty view:
mListview.setEmptyView(findViewById(R.id.empty_view));
the empty view is a textview directly below the listview in a linearlayout
the empty view xml:
empty_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/empty_list"
android:textColor="#color/lighter_gray"
android:layout_gravity="center"
android:gravity="center"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/no_item"
android:textStyle="italic">
</TextView>
I would suggest removing your empty view from the current layout file, and move it into its own dedicated layout file. Then inflate this new layout in your class when you want to use it as an empty view. The end result would be something like this (not compiled, coding from memory):
final View v = LayoutInflater.from(context).inflate(R.layout.empty_view, null);
mListview.setEmptyView(v);
or maybe
final View v = LayoutInflater.from(context).inflate(R.layout.empty_view, mListview, false);
mListview.setEmptyView(v);

Android: How to make Grid view with clickable grid items and nested views (buttons,Image) by remote(For Android TV)

How to make Grid view with click able grid items and nested views (buttons,Image) by remote(For Android TV)
I just want to click able image and button in grid view item should add to play my list if I navigate on button by Remote navigation not by touch
Thank you!!!
How to navigate through d pad in grid view sub items if grid view item have two sub items image button and another button
It is no difference between touch screen or remote control for methods like onClickListener or etc.
For remote control, you need to focus on the element first, than you can click the element.
I have not use the gridView on TV before, but I have used the recyclerView and scrollView. I think they have same situation.
I've try the default simpleAdapter to create the gridView, and it's no problem with the nested views that I can focus and click each grid items after I set the onItemClickListener to the gridView.
I guest your problem is that the grid item conflicts with the button in the grid item.
To avoid this situation, you need to set android:descendantFocusability="blocksDescendants" for the container of your custom grid item view. It will block the items statement in that parent layout.
If you want the button change in the different statement, you can give the button this parameter: android:duplicateParentState="true".
That will let the button follow it's parent's statement.
By the way, don't forget to set some changes to different statement for the grid items (background changes or etc), or you will not know which grid item you have focused :P.
Hope this will help you :)
PS. The following is the sample code for the custom grid item layout. Maybe the example can help you to understand what I mentioned easily.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:duplicateParentState="true"/>
</LinearLayout>
2015.01.06 23:11 update:
How to navigate through d pad in grid view sub items if grid view item
have two sub items image button and another button
For this case you should not use OnItemClickListener. Instead, you should make your grid item unfocusable and unclickable, and than set OnClickListener for both two buttons.
You can set the parameters in your customize adapter for the gridView. In getView method you can set each of the grid item view just like convertView.focusable(false) and convertView.clickable(false).
After that, you can set the click listener and give the method you want to do for the buttons in adapter.
Don't care about the D-pad action. Actually, D-pad will work automatically if there are elements can be focused.
The key point for this question is the conflict between grid item and its child elements. You could have just one part to be focused: grid item (the parent view), or the buttons (the child views).

How to show Empty List into Android ListView

I am currently developing application kind of notepad or Todo list. But I need to know to how to show empty list into listview, I guess android default ListView can not handle empty list view. Basically I need to show listview with no data, which I will add later, but initially the UI for listView should be empty.
Thank You!
this may helps you when there are no data in list
listview.setVisibility(View.INVISIBLE);
nodat.setVisibility(View.VISIBLE);
Hre nodata is Contain Empty Textview with SetText Your String like No Data
if you added the empty list into the adapter and that adapter set to listview then it will show you empty listview. after you add item to the list then you need to call notifydatasetchanged() of the adapter.
ListView as display initially empty till you add an item to the list and notify via adapter.
Note you must call method notifydatasetchanged() of an adapter when you populate the list item for add/edit/delete.
According to Developer Guidelines describing ListView you can easilty setup a TextViev, any other widget will be fine as well. Where you will encurage user to create ListItem.
Here is a snippet.
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
<TextView android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:text="No data"/>

Adding Empty Space to End of 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.

Categories

Resources