android³£ÓôúÂë´óÈ« ÏÂÔØ±¾ÎÄ

ÄÚÈÝ·¢²¼¸üÐÂʱ¼ä : 2025/6/15 18:02:43ÐÇÆÚÒ» ÏÂÃæÊÇÎÄÕµÄÈ«²¿ÄÚÈÝÇëÈÏÕæÔĶÁ¡£

¹ã¶«º£Ñó´óѧ´ç½ðѧԺ×ÛºÏʵϰ×ÊÁ϶þ Êڿΰ༶£º13¼ÆËã»ú1¡¢2°à ÊڿνÌʦ£ºÂÞ³ÉÔ£

imageTextView.imageView = list.get(position).imageView; }

return imageTextView; }

public void addItem(String text,Drawable drawable){ list.add(new ImageTextView(wcontext,text,drawable));//½«´´½¨ºÃµÄImageTextView¶ÔÏó¼ÓÈëµ½listÖÐÈ¥ } }

-------------------------------------------------------------------------------------------------------------------

public class ListView4Activity extends ListActivity {//¶¨ÖÆ×Ô¼ºµÄadapter

@Override

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

//setContentView(R.layout.main);//²»ÐèÒª´ËÏî ListCombinAdapter listCombinAdapter = new ListCombinAdapter(this);

listCombinAdapter.addItem(\²»ÖªµÀ´Ë´¦µÄ×Ö·û´®Æðʲô×÷ÓÃ\

listCombinAdapter.addItem(\²»ÖªµÀ´Ë´¦µÄ×Ö·û´®Æðʲô×÷ÓÃ\getResources().getDrawable(R.drawable.image3)); setListAdapter(listCombinAdapter); } }

================================================================================================================= µÚËĸöÀý×Ó£º simpleadapter2.xml

xmlns:android=\

¹ã¶«º£Ñó´óѧ´ç½ðѧԺ×ÛºÏʵϰ×ÊÁ϶þ Êڿΰ༶£º13¼ÆËã»ú1¡¢2°à ÊڿνÌʦ£ºÂÞ³ÉÔ£

android:orientation=\ android:layout_width=\ android:layout_height=\

android:layout_width=\ android:layout_height=\ android:drawSelectorOnTop=\ android:scrollbars=\

---------------------------------------------------------------------------------------------------------------------

xmlns:android=\ android:layout_width=\ android:layout_height=\ android:orientation=\ android:paddingLeft=\ android:paddingRight=\ android:paddingTop=\ android:paddingBottom=\

android:id=\ android:layout_width=\ android:layout_height=\ android:textSize=\

¹ã¶«º£Ñó´óѧ´ç½ðѧԺ×ÛºÏʵϰ×ÊÁ϶þ Êڿΰ༶£º13¼ÆËã»ú1¡¢2°à ÊڿνÌʦ£ºÂÞ³ÉÔ£

android:singleLine=\

android:id=\

android:layout_width=\ android:layout_height=\ android:gravity=\ android:textSize=\

--------------------------------------------------------------------------------------------------------------------- public class ListView1 extends ListActivity{//¼Ì³ÐµÄÊÇListActivity

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

ArrayList> list = new ArrayList>();

HashMap map1 = new HashMap(); HashMap map2 = new HashMap(); HashMap map3 = new HashMap(); map1.put(\ÕÅÈý\ map1.put(\µÚÒ»Ãû\ map2.put(\ÀîËÄ\ map2.put(\µÚ¶þÃû\ map3.put(\ÍõÎå\ map3.put(\µÚÈýÃû\ list.add(map1); list.add(map2); list.add(map3);

SimpleAdapter listAdapter = new SimpleAdapter(this,list,R.layout.simpleadapter2,

new String[]{\int[]{R.id.user_name,R.id.user_ip});

¹ã¶«º£Ñó´óѧ´ç½ðѧԺ×ÛºÏʵϰ×ÊÁ϶þ Êڿΰ༶£º13¼ÆËã»ú1¡¢2°à ÊڿνÌʦ£ºÂÞ³ÉÔ£

setListAdapter(listAdapter);//µ÷ÓÃListActivityÖеÄsetListAdapter()·½·¨ÉèÖÃÏÔʾListView } }

----------------------------------------------------------------------------------------------------------------------

* ´ËΪListActivityºÍlistViewÊý¾ÝÊÊÅäÆ÷ ¡£·½·¨ÖеĵÚÒ»²ÎÊýΪµ±Ç°¶ÔÏ󣬵ڶþ¸ö²ÎÊýΪ

* ÎÒÃÇÒªÓ³Éä³ÉMapdµÄList½á¹¹£¬µÚÈý¸ö²ÎÊýΪÿһÐÐÁбíµÄ²¼¾Ö£¨´Ë´¦ÎªÒ»ÐÐÏÔʾÁ½¸ölistView£©

* µÚËĸö²ÎÊýÊÇÒ»¸ö×Ö·û´®Êý×飬²¢¹æ¶¨ÁË˳Ðò£¬µÚÎå¸ö²ÎÊýÊÇÒÀ´Î°ÑµÚËĸö²ÎÊýµÄÎı¾ÒþÉäµ½listViewµÄ²¼¾ÖÖÐÈ¥

* ±¾ÊÊÅäÆ÷µÄ¸ñʽҲ¿ÉΪ£º(×¢ÒâÓ³ÉäµÄ˳Ðò) * setListAdapter(new

SimpleAdapter(this,list,R.layout.simpleadapter2,

new String[]{\int[]{R.id.user_name,R.id.user_ip});

======================================================================================================================= µÚÎå¸öÀý×Ó£ºÍ¨¹ýListViewÀ´ÏÔʾµç»°±¾ÖÐÐÅÏ¢¡£

ÏÈ´´½¨LinearLayout¶ÔÏóºÍListView¶ÔÏó£¬LinearLayoutÓÃÀ´ÏÔʾListView

È»ºóͨ¹ýListAdapter½«»ñµÃµÄµç»°±¾Êý¾ÝÓëListViewÁ¬½ÓÆðÀ´ ½Ó׎«ListAdapterÌí¼Óµ½ListViewÖÐ

×îºó½«ListViewÌí¼Óµ½LinearlayoutÖУ¬ÈÃÆÁÄ»ÏÔʾLinearLayout¡£ Òª´¦ÀíListViewʼþÐèҪΪÆäÌí¼ÓsetOnItemSelectedListener¼àÌýÒÔ¼°setOnItemClickListener¼àÌý Àý£º

public class ListView2 extends Activity{ LinearLayout linearLayout; ListView listView1;

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

¹ã¶«º£Ñó´óѧ´ç½ðѧԺ×ÛºÏʵϰ×ÊÁ϶þ Êڿΰ༶£º13¼ÆËã»ú1¡¢2°à ÊڿνÌʦ£ºÂÞ³ÉÔ£

linearLayout = new LinearLayout(this);//´´½¨LinearLayout²¼¾Ö¶ÔÏó----------------------------------------------------------ÔÚ´úÂëÖд´½¨LinearLayout

linearLayout.setOrientation(linearLayout.VERTICAL);//ÉèÖ÷½Ïò

linearLayout.setBackgroundColor(android.graphics.Color.BLUE);//ÉèÖñ³¾°É«

listView1 = new ListView(this);//´´½¨ListView¶ÔÏó LinearLayout.LayoutParams param = new

LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

listView1.setBackgroundColor(Color.BLACK);

linearLayout.addView(listView1,param);//Ìí¼ÓlistViewµ½linearlayoutÖÐÈ¥

setContentView(linearLayout);//ÉèÖÃÏÔʾLinearLayout²¼¾Ö //»ñÈ¡Êý¾Ý¿âPhonesµÄCursor Cursor cur =

getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,null);

startManagingCursor(cur);

//ListAdapterÊÇListViewºÍºǫ́Êý¾ÝµÄÇÅÁº¡£ //SimpleCursorAdapterÊǰÑÊý¾ÝÖвéѯµ½µÄ½á¹ûÓ³Éäµ½listViewÖÐ

ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2,//±íʾÿһÐеIJ¼¾Ö°üº¬Á½¸öÊý¾ÝÏî

cur,//Êý¾Ý¿âµÄCursor¶ÔÏó