ºÇ½ª¹¹¿·¡§
t_yokky2002 2011ǯ10·î17Æü(·î) 14:35:16ÍúÎò
¥ê¥¹¥È¤Î°ì¹Ô¤Î¤Ê¤«¤Ë¡¢²èÁü¤È¥Æ¥¥¹¥È¤¬´Þ¤Þ¤ì¤¿¥ì¥¤¥¢¥¦¥È¤ò¼Â¸½¤¹¤ë¤Ê¤É
Ê£»¨¤Ê¥ì¥¤¥¢¥¦¥È¤ËÂбþ¤¹¤ë¾ì¹ç¤Ï¡¢ArrayAdapter¤ò·Ñ¾µ¤·¤¿Æȼ«¤ÎAdapter¤ò¼ÂÁõ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
Ê£»¨¤Ê¥ì¥¤¥¢¥¦¥È¤ËÂбþ¤¹¤ë¾ì¹ç¤Ï¡¢ArrayAdapter¤ò·Ñ¾µ¤·¤¿Æȼ«¤ÎAdapter¤ò¼ÂÁõ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£
res/layout/custom_list_item.xml¤ò¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dip" > <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#ffffff" android:paddingTop="8dip" android:paddingBottom="8dip" android:paddingLeft="14dip" android:paddingRight="14dip" > <ImageView android:id="@+id/imageview" android:layout_width="85dip" android:layout_height="85dip" android:scaleType="centerCrop" android:padding="8dip" /> <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="1" android:textColor="@color/dark_blue" android:background="#ffffff" android:layout_marginLeft="16dip" android:layout_marginTop="8dip" /> </LinearLayout> </FrameLayout>
src/jp.co.example.listview/BindData.java¤ò¡¢¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
public class BindData { // ------------ ¢¤³¤³¤«¤é ------------------ private String text; private int imageResourceId; public BindData(String text, int id) { this.text = text; this.imageResourceId = id; } public String getText() { return text; } public void setText(String text) { this.text = text; } public int getImageResourceId() { return imageResourceId; } public void setImageResourceId(int imageResourceId) { this.imageResourceId = imageResourceId; } // ------------ ¢¬¤³¤³¤Þ¤Ç ------------------ }
src/jp.co.example.listview/ImageAdapter.java¤ò¡¢¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
public class ImageAdapter extends ArrayAdapter<BindData> { // ------------ ¢¤³¤³¤«¤é ------------------ private LayoutInflater inflater; public ImageAdapter(Context context, List<BindData> objects) { super(context, 0, objects); this.inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { // ¹Ô¤òɽ¤¹¥Ó¥å¡¼¥ª¥Ö¥¸¥§¥¯¥È¤ò¼èÆÀ convertView = inflater.inflate(R.layout.custom_list_item, parent, false); } // ²èÁü̾¤ÈÆüÉÕ¤Îɽ¼¨¥¨¥ê¥¢ TextView textView = (TextView) convertView.findViewById(R.id.textview); // ²èÁü¤Îɽ¼¨¥¨¥ê¥¢ ImageView imageView = (ImageView) convertView .findViewById(R.id.imageview); // ³ºÅö¥Ý¥¸¥·¥ç¥ó¤Î¥Ç¡¼¥¿¤ò¼èÆÀ BindData data = getItem(position); // ¥Æ¥¥¹¥È¥Ó¥å¡¼¤È¥¤¥á¡¼¥¸¥Ó¥å¡¼¤Ë¥»¥Ã¥È textView.setText(data.getText()); imageView.setImageResource(data.getImageResourceId()); return convertView; } // ------------ ¢¬¤³¤³¤Þ¤Ç ------------------ }
src/jp.co.example.listview/PhotoViewerActivity.java¤ò¡¢¼¡¤ÎÆâÍƤ˽ñ¤´¹¤¨¤Æ¤¯¤À¤µ¤¤¡£
public class PhotoViewerActivity extends ListActivity { // ------------ ¢¤³¤³¤«¤é ------------------ private Integer[] mThumbIds = { R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6 }; private String[] mTitles = { "image1\n\n2010/11/20", "image2\n\n2010/11/21", "image3\n\n2010/11/22", "image4\n\n2010/11/23", "image5\n\n2010/11/24", "image6\n\n2010/11/25" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.custom_list); // BindData¤Î¥ê¥¹¥È¤òÀ¸À®¤·¡¢¥¢¥À¥×¥¿¡¼¤Ë¥»¥Ã¥È List<BindData> objects = new ArrayList<BindData>(); for(int i = 0; i < mTitles.length; i++) { BindData data = new BindData(mTitles[i], mThumbIds[i]); objects.add(data); } setListAdapter(new ImageAdapter(this, objects)); } // ------------ ¢¬¤³¤³¤Þ¤Ç ------------------ }
¤³¤Î¥Ú¡¼¥¸¤Ø¤Î¥³¥á¥ó¥È
vqAxQ6 <a href="http://fowsnumrdhop.com/">fowsnumrdhop</a>, [url=http://mwllmkxnswez.com/]mwllmkxnswez[/url], [link=http://jbuzvfzvlogf.com/]jbuzvfzvlogf[/link], http://ybqhoejhkvdp.com/