Android Base controls use details--listview

Source: Internet
Author: User

This series has been prepared for a long time, because the project is relatively tight, and has not been writing blog.


ListView is the use of a wide range of Android development control, here will be the actual development of the problem, do a summary, and constantly updated to supplement, I hope to help more friends in the future!


Sometimes in order to streamline the code, do not use the XML layout file, direct Setcontentview (Mlistview), and then the code will be used to hard-coded ListView style, I developed a wonderful problem encountered, to set the ListView to a split line, No effect, rub, pit Dad, find a lot of information, encountered this problem is not me a person, unexpectedly no one solved, someone even compromised, using the XML file, which is actually the problem of Android code, Setdivider and Setdividerheight order must be one after the Upside down is not good, suddenly feel that their brains are not enough to use ha. Just remember, all right! No spicy, more horse for God!

Set the style of the list ListView Mlistview = (listview) Findviewbyid (R.id.mlistview); Mlistview.setbackgroundcolor ( Color.parsecolor ("#F1F1F1")); Mlistview.setpadding (a), mlistview.setverticalscrollbarenabled (false);// Android blunder: Set the split Line color (these two lines of code position cannot be reversed otherwise no effect) Mlistview.setdivider (new Colordrawable (color.transparent)); Mlistview.setdividerheight (6); Setcontentview (Mlistview);

Then a ListView, and then set an empty interface (when the list is not data when the display of the warm hint), here need to add the ListView parent, of course, can not use XML, can also hard code new out a layout, Because I want to show special picture effect in my project, I can only still ache love cuts XML layout file. Later I'll write the sample code for the XML to complete the ListView and Emptyview.

Setting the list to an empty display interface Layoutinflater Inflater = Layoutinflater.from (Mcontext); View view = Inflater.inflate (R.layout.layout_empty, NULL);((ViewGroup) mlistview.getparent ()). AddView (view); I Mageview empimg = (ImageView) Findviewbyid (r.id.empimg); TextView Emptip = (TextView) Findviewbyid (R.id.emptip); Empimg.setimageresource (R.drawable.ic_logo_empty); Emptip.settext ("No relevant data"); Mlistview.setemptyview (view);














Android Base controls use details--listview

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.