Learn about the usage of viewstub instances and the magical use of TextView with drawable

Source: Internet
Author: User

In the project, we may have a variety of data sources such as:

There is a ListView in it, and there is empty information displayed when the data is empty. Depending on whether you clicked on the item or the errand, the empty message displayed is different. A. There are no items for collection, and B does not currently have a collection of errands.

In fact there are many ways to achieve. can also be achieved. But it's most appropriate to use viewstub here.

Let's look at the layout of this activity. Layout file:

<
framelayout android:id= "@+id/layoutfrm"
        android:layout_width= "Match_parent"        android:layout_height= "0DP"         android:layout_weight= "1"        android:background
= "@color/background_color" > < ListView xmlns:ptr= "Http://schemas.android.com/apk/res-auto"
            android:id= "@+id/lstv_fav_task"            -----------Some of you know-------            Ptr:ptrmode
= "Pullfromend" > </ Com.handmark.pulltorefresh.library.PullToRefreshListView> < viewstub android:id= "@+id/viewstub"
            android:layout_gravity= "center"            android:layout_width= "Match_parent"              android:layout_height= "Wrap_content"            android:layout
= "@layout/activity_task_favourite_nodata" /> </framelayout>

Initialize it in the code! And where is the activity_task_favorite_nodata of the viewstub loaded layout file?

Look at the layout:

<? XML version= "1.0" encoding= "Utf-8" ?> < TextView xmlns:android = "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/txtv_nodata"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"android:drawablepadding= "20DP"Android:drawabletop= "@drawable/favourite_nodata"android:gravity= "Center_horizontal"Android:text= "@string/my_task_fav_nodata"Android:textcolor
= "@color/listview_header_textcolor" />

That is to say that the layout of the interface is actually a textview. Make a half day, I thought also want to engage a textview also want tall imageview, weak explode, what all do not understand come out to see people write I again tragedy.

(This is the Drawable/favourite_nodata.png file)

What do you do in the code? Set to not visible (pre-loaded) dry first. Not hard. Key brother does not study.

Layoutempty =
(TextView) viewstub.inflate ();        Layoutempty.setvisibility (View.gone);

Sure to get the data. There's got to be a way. Over here:

Private void getfavprojects ()
Get the data, Judge Datalist.size ... Have a ... Below you know
Private void setemptyviewbydatalist (int  type) {        if (datalist.size () > 0) {            layoutempty.setvisibility (view.gone);         Else {            if (type = = type_project)                Layoutempty.settext (r.string.my_project_fav_ NoData);             Else                 Layoutempty.settext (r.string.my_task_fav_nodata);            Layoutempty.setvisibility (view.visible);        }    }

Learn about the usage of viewstub instances and the magical use of TextView with drawable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.