I've a ListView
that can have 0 custom items inside (like "My Downloads").
Is there anyway to show a default text "No download yet" ?
Thanks !
EDIT : here is my solution,
TextView emptyView = new TextView(getApplicationContext()); emptyView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); emptyView.setTextColor(R.color.black); emptyView.setText(R.string.no_purchased_item); emptyView.setTextSize(20); emptyView.setVisibility(View.GONE); emptyView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); ((ViewGroup)getListView().getParent()).addView(emptyView); getListView().setEmptyView(emptyView);
public void setEmptyView (View emptyView) Since: API Level 1 Sets the view to show if the adapter is empty
Called on your ListView instance.
E.g. mListView.setEmptyView(someView);
You can build view on the fly, or inflate one from the xml.
Unless I misread your question, you can also just specify any view element with an ID of "@android:id/empty" in your layout and it will be taken care automatically for you. For example:
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:visibility="visible"/> <LinearLayout android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center"> <TextView android:text="@string/no_messages" android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/textBoldLight"> </TextView> </LinearLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With