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