大佬教程收集整理的这篇文章主要介绍了自定义ListView Android,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
SimpleAdapter adapter = new SimpleAdapter(this,this.dh.SELEctAll(),R.layout.custom_row_view,new String[] {"Icon","Chance","TeamID"},new int[] {R.id.text1,R.id.text2,R.id.text3}); setlistadapter(adapter);
这是我的简单适配器.我想把它们放进去,我能做到吗?
package com.TestActivity; import java.util.ArrayList; import java.util.HashMap; import android.app.ListActivity; import android.os.bundle; import android.widget.SimpleAdapter; public class MyList extends ListActivity { final static ArrayList<HashMap<String,?>> data = new ArrayList<HashMap<String,?>>(); static{ HashMap<String,Object> row = new HashMap<String,Object>(); row.put("Icon",R.drawable.flags_albania); row.put("Chance","65%"); row.put("TeamID","Albania"); data.add(row); row = new HashMap<String,R.drawable.flags_rpa); row.put("Chance","55%"); row.put("TeamID","RPA"); data.add(row); row = new HashMap<String,R.drawable.flags_polska); row.put("Chance","100%"); row.put("TeamID","Polska :)"); data.add(row); } @Override public void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.row,new int[] { R.id.imageView1,R.id.textView1,R.id.textView2}); setlistadapter(adapter); } }
RES /布局/ row.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://scheR_546_11845@as.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@+id/imageView1"/> <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
把带有标志的pngs放到res / drawable-hdpi /
flags_albania.png
flags_rpa.png
flags_polska.png
你会得到这样的东西:
以上是大佬教程为你收集整理的自定义ListView Android全部内容,希望文章能够帮你解决自定义ListView Android所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。