The custom control is used here to customize the listview.
Package COM. example. demo; import android. content. context; import android. util. attributeset; import android. view. motionevent; import android. widget. adapterview; import android. widget. listview;/*** rounded listview */public class listcorn extends listview {public listcorn (context) {This (context, null);} public listcorn (context, attributeset attrs) {super (context, attrs); // The rounded corner background of the entire listview this. setbackgroundresource (R. drawable. corner_list_bg);} @ override public Boolean onintercepttouchevent (motionevent eV) {Switch (ev. getaction () {Case motionevent. action_down: int x = (INT) eV. getx (); int y = (INT) eV. gety (); int itemnum = pointtoposition (x, y); If (itemnum = adapterview. invalid_position) {break;} else {If (itemnum = 0) {If (itemnum = (getadapter (). getcount ()-1) {// only one setselector (R. drawable. corner_list_single_item);} else {// The first setselector (R. drawable. corner_list_first_item) ;}} else if (itemnum = (getadapter (). getcount ()-1) {// The Last setselector (R. drawable. corner_list_last_item);} else {// intermediate item setselector (R. drawable. corner_list_item) ;}} break; Case motionevent. action_up: break;} return Super. onintercepttouchevent (EV );}}
Then apply it to the layout file.
<com.example.demo.ListCorn android:id="@+id/ydlist" android:layout_below="@+id/edit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_margin="10dp" android:cacheColorHint="#00000000" android:scrollbars="none" > </com.example.demo.ListCorn>