Android listview style settings

Source: Internet
Author: User
From: http://hi.baidu.com/spare_h/blog/item/10406ba3c0e163b5caefd043.html

Attentive friends should find that after the background is set in listview. There will be some problems.

1. When the listview is dragged, the background image disappears into a black background. After the drag is completed, our own background image will be displayed.

2. There is a black shadow on the top and bottom of the listview.

3. Set an image as the interval between each item in lsitview.

Set the statement in the XML file of listview to solve the above problem.

Question 1: complete the following code to solve Android: scrollingcache = "false"

Problem 2: Use the following code to solve the problem: Android: fadingedge = "NONE"
Problem 3: Use the following code to solve the problem: Android: divider = "@ drawable/list_driver" where @ drawable/list_driver is an image resource.

Overall:

<Listview
Android: Id = "@ + ID/mylistview01"
Android: layout_width = "fill_parent"
Android: layout_height = "287dip"
Android: fadingedge = "NONE"
Android: divider = "@ drawable/list_driver"
Android: scrollingcache = "false"
Android: Background = "@ drawable/List">
</Listview>

 

 

Listview background and eidttext word limit and prompt

1. After setting the background in listview, if you click the blank button, you will find that the background has returned a black one,

This is because the background of the system is called again.

Therefore, you need to set

Android: Background = "# ffffff"
Android: cachecolorhint = "# ffffff"
Try to be the same

2. If you want to set editvtext, use the code to limit the number of words

Textview TV = new textview (this );
Int maxlength = 10;
Inputfilter [] farray = new inputfilter [1];
Farray [0] = new inputfilter. lengthfilter (maxlength );
TV. setfilters (farray)
3. If you want to tell others the maximum number of words at this time, you want to bring up a dialog box, but at this time, because there is an input method, you cannot bring up all the information that you want to cancel the input method before you can use it. Therefore, you need to remove the input method.

Inputmethodmanager Imm = (inputmethodmanager) getsystemservice (context. input_method_service );
Imm. hidesoftinputfromwindow (edittextfield. getwindowtoken (), 0 );

 

You may want to use the onkeylistener event of edittext, but when a word is not written, it still cannot respond to this event as it does not match the word count

All input methods must be canceled first.

 

Set the split line divider style for listview using the program method in Android

When using XML, you can use the Android: divider attribute to set the split line style (color or resource file) for listview. The default method provided in Java code is

Listview. setdivider ()

It only supports drawable resource files, so it takes a little time to solve the problem. Later, it was found that it is actually very simple. Android provides the method to create color resource files, so you only need to use

Listview. setdivider (New colordrawable (color ))

You can solve the problem.

PS: If the divider setting does not work, remember to set dividerheight to a non-zero value.

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.