I have a ListView with an empty list catch in the XML and it works fine. How to toggle ListView Empty Text please ?
This is my XML code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/emptyList" />
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
I'm not using a ListActivity. It s possible to do that please ?
You just need to make use of setEmptyView(View v):
person_ListView.setEmptyView(root.findViewById(R.id.empty));
offtopic: ListActivity is using this method also, but with android.R.id.empty.
Related
ListFragment by defaults shows a progressbar while the data get loaded. I plan on putting the listfragment in xml file and have it show progressbar till I get the data from the server.
The reason I m trying to put listfragment inside xml is because in my layout I have a linearlayout above the place where I plan to put listfragment.
Here is my xml file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/filterHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/white"
>
<ToggleButton
android:id="#+id/filterToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:textColor="#color/black"
android:textOff="#string/filterToggleButtonText"
android:textOn="#string/filterToggleButtonText"
android:drawableLeft="#drawable/filter_small"
/>
</LinearLayout>
<fragment
andorid:name="in.coupondunia.androidapp.testListFragment"
android:id="#+id/couponsByCategoryFragment"
android:layout_below="#id/filterHolder"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
Have you tried using http://developer.android.com/reference/android/app/ListFragment.html#setListShown(boolean) with parameter true? From the docs it might work.
There is a ListView in layout of my Activity.
listview_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/MyListView" />
</LinearLayout>
I am using another layout for ListItem of ListView.
listitem_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txtTitle"
android:layout_width="80dp"
android:layout_height="wrap_content" />
<Spinner
android:id="#+id/MySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
My Activity’s layout is the same with the listview_layout.xml’s.
I use SimpleAdapter cited the layout of listitem_layout.xml.
The problwm: Now I want to get the Spinner control ID of listview_layout.xm.
I use findViewById(MySpinner) in activity of ListView, it has the error of null pointer exception.
can not find. Because the Activity layout files use the listview_layout.xml’s and Spinner control in listview_layout.xml.
anyone's help is very thankful.
you cannot directly use the findViewById(spinnerId). You have to override the getView() method of Custom Adapter instead of Simple Adapter and inside that inflate the listitem_layout to a view(v) and then use v.findViewById(spinnerId).
Refer the below link which will help you in creating custom adapter (Weather Adapter in the link's example). in the example ImageView object is created in the GetView method. Instead of that you use Spinner.
I have a layout with this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/fundo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/consoleListaSimples"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/listaSimples"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
and for which item from the list a have this xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/bk_principal_small">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imagemStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/green"/>
<TextView
android:id="#+id/texto1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/padrao" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
and to create the itens I create a SimpleAdapter that I insert the data using the method ListAdapterCreater
this.adapter = new ListAdapterCreater(list.getContext(),itensList,
R.layout.list_simple_item,new String[] {"text","image"},
new int[]{R.id.texto1,R.id.imagemStatus});
to set the text works pretty, but doesn`t work for the image.
what have to be the value of image? or what should I change to works?
Refer the below links which have sample code snippets.
LINK1 it has one textview and one image view in each list item.
LINK2 it has two textview in each list item.
LINK3 it has two textview and one image view in each list item.
I believe you'll have to create new Adapter that extends BaseAdapter.
Here's a few tutorials for you:
http://blog.sptechnolab.com/2011/02/01/android/android-custom-listview-items-and-adapters/
http://w2davids.wordpress.com/android-listview-with-iconsimages-and-sharks-with-lasers/
If you look closely on those tutorials, the trick lies in how getView() work.
My class extends a ListActivity, I would like to have a title bar just as "Sound settings" in the following image;
What would be the proper way to create such title.
Thank you for your time.
Creating custom layout can solve this problem.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:orientation="vertical"
<TextView android:id="#+id/textViewCategoriesTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/categoriesTitle"
android:background="#123"
android:layout_gravity="center_horizontal"
android:textSize="30sp" />
<ListView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/listViewCategories"
android:layout_gravity="center_vertical|center_horizontal" />
</LinearLayout>
Hope this can help.
You could add a header view to the list view :
getListView().addHeaderView(myTitleView);
I'm not sure how you can be sure to get the exact same look, though. I would try with just a basic layout containing a TextView and see how that works out.
I have a simple ListActivity that uses a ListAdapter that I'd like to customize the ListView for. Here is my onCreate, where I specify to use a View rather than using the default ListView generated by setListAdapter():
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set the listview, empty listview
setContentView(R.layout.main);
getListView().setEmptyView(findViewById(android.R.id.empty));
// set the list properties
getListView().setOnCreateContextMenuListener(this);
.
.
.
<code snipped>
.
.
.
setListAdapter(adapter);
}
You can see that I am setting the emptyView as well. Here is the XML file main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="vertical"
android:dividerHeight="5dp" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:singleLine="false"
android:text="#string/message_empty_list" />
</LinearLayout>
My problem is that the ListView, while applying the dividerHeight correctly, is ignoring the :fadingEdge directive when it is in the XML; however, if I set the fadingEdge programatically, it works, i.e.:
getListView().setVerticalFadingEdgeEnabled(true);
Any ideas why the listview would be ignoring the fadingEdge specifically? Am I doing something incorrectly that could be leading to this behavior?
Thanks!
android:id="#id/android:list"
should be
android:id="#iandroid:id/list"
I'm not even sure why that compiles.
This is how you should be using custom xml for listactivities.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data found"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>