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.
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.
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.
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.
Im having trouble with implementing list view inside a fragment.
the xml code is:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/jo_logo" />
</LinearLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
simple ImageView and afterwards the list view.
I've already tried to implement:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(),
android.R.layout.simple_list_item_1, viewList);
setListAdapter(adapter);
where viewList is View[], on the onCreateView function.
seems that it's not working that way inside fragment.
thing is i need that the first view will be ImageView and second one is ListView, and all inside the Fragment.
please help, thank in advance, udi
In your layout xml change android:id="#+id/listView1" to android:id="#android:id/list" otherwise the ListActivity / ListFragment won't find your ListView.
By using the following code.
BuyActivity.java
public class BuyActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.transaction_list_view);
OrderAdapter orderAdapter = new OrderAdapter(this,
R.layout.custom_row_view, new ArrayList<Object>());
setListAdapter(orderAdapter);
orderAdapter.add(new Object());
orderAdapter.add(new Object());
}
}
transaction_list_view.xml
<?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">
<ListView android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"
/>
</LinearLayout>
custom_row_view.xml
Please refer to custom_row_view.xml
I was able to get the following outcome.
Besides list, I would also like to have a static label at the bottom of ListActivity.
I try
transaction_list_view.xml
<?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">
<ListView android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="#id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="THIS IS TOTAL STATIC LABEL"
/>
</LinearLayout>
But I am getting
What my expectation is
Is there anything I had missed out?
You have indicated that your ListView is supposed to fill_parent in the vertical orientation, leaving no room for your other widgets. Your weight is being ignored. You probably want to have your android:layout_height be 0dip instead.
Try setting the height of the static textview to wrap_content.
Well you could try Relative Layout to just set the static label anchored to the bottom of the screen. If that's not what you meant, I would try to help you further on. Good luck