2012年3月26日星期一

Coach BagPublic class TitleList extends ListActivity private String mListTitle = &quot

Public class TitleList extends ListActivity {private String mListTitle = {" ;the name " ," ;" ;gender ;age ," ;" ," ;" ," ;residence ;;" ;} ;private String mListStr = {" ;rain loose ,MOMO" ;" ," ;male ;" ;25" ;" ;" ,Beijing ;" xuanyusong@gmail.
com" ,;;} ;ListView mListView = null ;ArrayList< ;Map< ;String ,Object> ;> ;mData = new ArrayList< ;Map< ;String ,Object> ;> ;( ) ;Override protected void ;@ onCreate ( Bundle savedInstanceState ) {mListView = getListView ( ) ;int lengh = mListTitle.
length ;for ( int i = 0 ;I < ;lengh ;I + + ) {Map< ;String ,Object> ;item = new HashMap< ;String ,Object> ;( ) ;item.put ( " ;title" ;mListTitle , ) ;item.
put ( " ;text" ,mListStr I ; ) ;mData.add ( item ) ;} SimpleAdapter adapter = new SimpleAdapter ( this ,mData ,Nike Factory Outlet,android.R.layout.simple_list_item_2 ,new String {" ;title" ;text" ," ;New Int ;} , {android.
R.id.text1 ,android.R.id.text2} ) ;setListAdapter ( adapter ) ;mListView.setOnItemClickListener ( New OnItemClickListener ( ) {@ Override public void onItemClick ( AdapterView< ;> ;adapterView ,View ?View ,int position ,long ID ) {Toast.
makeText ( TitleList.this ," ;you choose the title: " ;+ mListTitle + " ;content :" + mListStr ;,Toast.LENGTH_LONG ) . Show ( ) ;} } ) ;super.onCreate ( savedInstanceState ) ;} } 3 with pictures of the ListView list using the simpleAdapter to operate but constructed simpleAdapter when need to use to write our own layout to complete ,because the system layout has been unable to meet the demand ,the same Map< ;String ,Object> ;item to save each item in the list to display such as caption content .
Public class IconList extends ListActivity {private String mListTitle = {" ;the name " ," ;" ;gender ;age ," ;" ," ;" ," ;residence ;;" ;} ;private String mListStr = {" ;rain loose ,MOMO" ;" ," ;male ;" ;25" ;" ;" ,Beijing ;" xuanyusong@gmail.
com" ,;;} ;ListView mListView = null ;ArrayList< ;Map< ;String ,Object> ;> ;mData = new ArrayList< ;Map< ;String ,Object> ;> ;( ) ;Override protected void ;@ onCreate ( Bundle savedInstanceState ) {mListView = getListView ( ) ;int lengh = mListTitle.
length ;for ( int i = 0 ;I < ;lengh ;I + + ) {Map< ;String ,Object> ;item = new HashMap< ;String ,UGG Clearance,Object> ;( ) ;item.put ( " ;image" ;item.put ,R.drawable.jay ) ;( " ;title" ;mListTitle , ) ;item.
put ( " ;text" ;mListStr , ) ;} mData.add ( item ) ;SimpleAdapter adapter = new SimpleAdapter ( this ,mData ,R.layout.iconlist ,new String {" ;image" ;" ;title" ;" ,text" ,;;} ,new int {R.
id.image ,R.id Title ,Coach Bag,R.id.text} ) ;setListAdapter ( adapter ) ;mListView.setOnItemClickListener ( New OnItemClickListener ( ) {@ Override public void onItemClick ( AdapterView< ;> ;adapterView ,View ?View ,int position ,long ID ) {Toast.
makeText ( IconList.this ," ;you choose the title: " ;+ mListTitle + " ;content :" ;+ mListStr ,Toast.LENGTH_LONG ) . Show ( ) ;} } ) ;super.onCreate ( savedInstanceState ) ;} } 4 custom layout BaseAdapter modify the list of colors because by directly constructing system layout to draw list method is limited ,so we need to override the draw method ,to write a class to inherit from the BaseAdapter and the realization of this method in the class ,listView at the beginning to draw it will first call getCout ( ) method to obtain the drawing number ,and then instantiates its own definition of the BaseAdapter through the getView ( ) method, a layer of ListView drawing ,so we can here according to the position ( current mapping of the ID ) to arbitrary modify drawing content ,make a good-looking beautiful ListView ,this example below I by overriding the getView modification List of each color and the realization of the user selected into the highlighted state .
5 custom layout ArrayAdapter ArrayAdapter BaseAdapter subclass ,ArrayAdapter not only has all of BaseAdapter method also customize some new methods to treat the list item ,so from a simple function can speaking ArrayAdapter far stronger and BaseAdapter ,if it is a draw some small amount of the list of suggested using BaseAdapter if to draw some of the more complex list item and many of the recommendations for the use of ArrayAdapter list item .
< ;?XML version = " ;1.0" ;encoding = " ;utf-8" ;> ;< ;RelativeLayout ?Xmlns : Android = " ;http: / / schemas.android.com / APK / RES / android" ;Android: layout_width = " ;fill_parent" ;Android: layout_height = " ;wrap_content" ;> ;< ;Buttonandroid: id = " ;@ + ID / array_button" ;Android: layout_width = " ;wrap_content" ;Android: layout_height = " ;wrap_content" ;Android: text = " ;a button " / > ;< ;ImageView ;Android : id = " ;@ + ID / array_image" ;Android: layout_toRightOf = " + ID / array_button" ;@ ;Android: layout_width = " ;wrap_content" ;Android: layout_height = " ;fill_parent" ;Android: layout_alignParentTop = " ;true" ;Android: layout_alignParentBottom = " ;true" ;Android: adjustViewBounds = " ;true" ;Android: padding = " ;2dip" ;< ;TextView / > ;Android : id = " + ID ;@ / array_title" ;Android: layout_width = " ;fill_parent" ;Android: layout_height = " ;wrap_content" ;Android: layout_toRightOf = " ;@ + ID / array_image" ;Android: layout_align ParentBottom = " ;true" ;Android: layout_alignParentRight = " ;true" ;Android: singleLine = " ;true" ;Android: ellipsize = " ;marquee" ;Android: textSize = " ;15dip" ;< ;TextView / > ;Android : id = " ;@ + ID / array_text" ;Android: layout_width = " ;fill_parent" ;Android: layout_height = " ;wrap_content" ;Android: layout_toRightOf = " ;@ + ID / array_image" ;Android: layout_below = " ;@ + ID / array_title" ;Android: layout_alignParentBottom = " ;true" ;Android: layout_alignParentRight = " ;true" ;Android: singleLine = " ;true" ;Android: ellipsize = " ;marquee" ;Android: textSize = " ;20dip" ;> ;< ;public class ArrayList / RelativeLayout> ;extends ListActivity {private String mListTitle = {" ;the name " ," ;" ;gender ;age ," ;" ," ;" ," ;residence ;;" ;} ;private String mListStr = {" ;rain loose ,MOMO" ;" ;" ," ;male ;25" ;" ;" ,Beijing ;xuanyusong@gmail.
com" ,Outlet Coach Store," ;ListView mListV ;} ;Iew = null ;MyListAdapter myAdapter = null ;ArrayList arrayList = null Override protected void ;@ onCreate ( Bundle savedInstanceState ) {arrayList = this ;mListView = getListView ( ) ;myAdapter = new MyListAdapter ( this ,R.
layout.arraylist ) ;setListAdapter ( myAdapter ) ;super.onCreate ( savedInstanceState ) ;} public class MyListAdapter extends ArrayAdapter< Object> ;{ ;int mTextViewResourceID = 0 ;private Context mContext ;public MyListAdapter ( Context context ,int textViewResourceId ) {super ( context ,textViewResourceId ) ;mTextViewResourceID = textViewResourceId ;mContext = context ;} private int colors = New Int {0xff626569 ,Moncler Outlet Store,0xff4f5257} ;public int getCount ( ) {return mListStr.
length ;} @ Overridepublic Boolean areAllItemsEnabled ( ) {return false ;} public Object getItem ( int position ) {return position ;} public long getItemId ( int position ) {return position ;} public View getView ( final int position ,View convertView ,ViewGroup parent ) {ImageView iamge = null ;TextView title = null ;TextView text = null ;Button button = null ;if ( convertView = = null ) {convertView = LayoutInflater.
from ( mContext ) . Inflate ( mTextViewResourceID ,null ) ;iamge = ( ImageView ) convertView.findViewById ( R.id.array_image ) ;title = ( TextView ) convertView.findViewById ( R.
id.array_title ) ;text = ( TextView ) convertView.findViewById ( R.id.array_text ) ;button = ( Button ) convertView.findViewById ( R.id.array_button ) ;button.setOnClickListener ( New OnClickListener ( ) {@ Override public void onClick ( View arg0 ) {Toast.
makeText ( arrayList ," ;you click on the " + position + " ;;buttons ," ;Toast.LENGTH_LONG ) . Show ( ) ;} } ) ;} int colorPos = position% colors.length ;convertView.
setBackgroundColor ( colors ) ;title.setText ( mListTitle ) ;text.setText ( mListStr ) ;if ( colorPos = = 0 ) iamge.setImageResource ( R.drawable.jay ) ;elseiamge.setImageResource ( R.
drawable.image ) ;return convertView ;} } } end if you still think I write not detailed enough not to look cool me tight The source code to download address affixed to welcome everyone to learn together to discuss rain loose MOMO hope we can progress together .
Related articles:

没有评论:

发表评论