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"/>
Related
I have a ListView with Pull to Refresh. After refreshing the ListView, it moves to the top. But I want to show the item added newly to the ListView. How to implement it, Can anyone help me. Thanks in advance.
Use this attribute android:stackFromBottom="true", because it always add new item at bottom of list view. Like following code,
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:divider="#null"
android:stackFromBottom="true" >
</ListView>
And add one more thing add in your code,
[listView].smoothScrollToPosition([adapter].getCount() - 1);
I think this topic has the answer you want in addition to Ando Masahashi's answer : https://stackoverflow.com/a/3505869/1506369
You can add reFill method to your adapter, for example:
public void reFill(List<MyData> newData){
this.myData.clear();
this.myData.addAll(newData);
}
So, after refreshing the ListView and getting new data, you call this method of adapter and set new data, and call notifyDataSetChanged() on adapter. If you doing this, ListView doesn't move to the top.
i want change the order of listview to be the recent items added be in the top of listview , old be last down
i get the data from sqlite , then fill them to arraylist of objects called reports_items_obj
i use custom adpater to view
ListView list_messages = (ListView) findViewById(R.id.list);
Report_adapter adapter = new Report_adapter(getApplicationContext(), reports_items_obj);
list_messages.setAdapter(adapter);
xml file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>
</LinearLayout>
The order in which listview is based on the order of items in arraylist or cursor or from whereever the data is stored which will be populated in the listview. So try changing the order of arraylist.
Solution lies in the data source. Lets say you are getting the data from a sqlite db, when you are querying the db use order by desc on a column.
You need to specify the data source to give a complete answer.
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" />
I try to change the content of a Listview in Android. After that I want the list to be redrawn. Unfortunately the list elements change, but the old items are displayed in the background. If there are less items in the new list it seems like the old items are still part of the list, as they are still displayed, even though they are not clickable. If I jump out of the app via the Android Taskmanager and afterwards open the app again, the list gets displayed correctly!
Therefore I think it must be a problem with refresh.
How do I try to achieve it:
As the complete content changes I create a new adapter that I pass to the ListView. In my code "favorites" is the new Array that I pass to the adapter. I also try to clear the list and invalidate it. all of this happens in the UI thread (onPostExecute of AsyncTask)
MyAdapter newAdapter = new MyAdapter(
context, favorites);
MyAdapter current_adapter = (MyAdapter) myList.getAdapter();
if((current_adapter!=null)){
current_adapter.clear();}
myList.setAdapter(null); //inserted this because of answers, but with no effect.
myList.setAdapter(newAdapter);
myList.invalidateViews();
The clear method of the adapter:
public void clear(){
items.clear();
notifyDataSetChanged();
}
As you can see I tried all of the solutions to similar problems her on stackoverflow. Unfortunately nothing worked...
Thanks in advance for any ideas how to solve this.
Edit:
I have also tried to set the adapter null before passing the new one, also with no effect.
.setAdapter(null);
Also if I open the keyboard by clicking in a editText, the screen refreshs and the list is displayed correctly.
Have you tried myList.setAdapter(null); ?
I solved the problem by filling the remaining space under the list with a layout with more layout_weight than the ListView. This way the "extra" lines are hidden.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent"
android:orientation="vertical" >
<ListView
android:id="#+id/main_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/aux_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/transparent"
android:orientation="vertical" />
</LinearLayout>
I tried that and I discovered HardwareAcceleration has to be set to TRUE (what is also default value) in application tag in your manifest file. Otherwise listView will keep old non-clickable items in its background during typing.
android:hardwareAccelerated="true"
First clear the data. I think it's favorites or items or whatever. and notify the adapter in this way.
items.clear();
((MyAdapter) myList.getAdapter()).notifyDataSetChanged();
MyAdapter newAdapter = new MyAdapter(context, favorites);
myList.setAdapter(newAdapter);
myList.invalidate();
I have Created a ListView and set a background image.Everything goes fine except I am unable to click on the right side of the row of ListView.Can anybody help me this.
Below is the xml file...
<ListView
android:layout_width="wrap_content"
android:id="#+id/JSONListView"
android:layout_height="wrap_content"
android:background="#drawable/listbg"
android:focusable="false"
android:cacheColorHint="#00000000"
android:visibility="visible" >
</ListView>
And I am not using any View.
Use the attribute
android:layout_width="match_parent"
and set click listener for items.
I guess you have created your custom adapter. If so, just go to the getView() method of that custom adapter and on the holder instance of that portion of listitem add a onCLickListener.
Provide more info. XML layout, etc.
Im guessing there is a view there or it is not filling the entire width but difficult to say.
Android ListView Activity