Á¦°¡ ±¸Çö ÇÒ·Á°í ÇÏ´Â Æ®¸® ¸ð¾çÀº
óÀ½ Ãâ·Â µ¥ÀÌÅÍ
|
¿ø ÇÏ´Â °á°ú(TreeItem02 Ŭ¸¯½Ã)
|
Ãâ·ÂµÇ´Â °á°ú(TreeItem02 Ŭ¸¯½Ã)
|
----------
TreeItem01
TreeItem02
TreeItem03
-----------
|
----------
TreeItem01
TreeItem03
-----------
|
----------
TreeItem01
(ºó °ø°£)
TreeItem03
-----------
|
À§¿Í °°Àº °á°ú¸¦ ¾ò°í ½ÍÀºµ¥,
¾îÁ¦ ÇÏ·çÁ¾ÀÏ °í¹ÎÀÌÇÏ´Ù °á±¹ ÀÌ·¸°Ô ¿Ã¸®³×¿ä.¤Ð¤Ð
¼Ò½º´Â ¾Æ·¡¿Í °°½À´Ï´Ù.
Á¶¾ð, Ãæ°í, Á¤º¸ ¸ðµçÁö ȯ¿µÀÔ´Ï´Ù..¤Ð¤Ð µµ¿ÍÁֽʼî¤Ð¤Ð
public class C09_ListIconText extends Activity {
ArrayList<MyItem> arItem;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.c09_listview);
arItem = new ArrayList<MyItem>();
MyItem mi;
mi = new MyItem(R.drawable.icon, "»ï¼º ³ëÆ®ºÏ"); arItem.add(mi);
mi = new MyItem(R.drawable.icon, "LG ¼¼Å¹±â"); arItem.add(mi);
mi = new MyItem(R.drawable.icon, "´ë¿ì ¸¶Æ¼Áî"); arItem.add(mi);
MyListAdapter MyAdapter = new MyListAdapter(this, R.layout.c09_icontext, arItem);
ListView MyList;
MyList=(ListView)findViewById(R.id.list);
MyList.setAdapter(MyAdapter);
MyList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String mes;
mes = "Select Item = " + arItem.get(position).Name;
Toast.makeText(C09_ListIconText.this, mes,Toast.LENGTH_SHORT).show();
parent.getChildAt(position).setVisibility(View.GONE);
}
});
}
}
//¸®½ºÆ® ºä¿¡ Ãâ·ÂÇÒ Ç׸ñ
class MyItem {
MyItem(int aIcon, String aName) {
Icon = aIcon;
Name = aName;
}
int Icon;
String Name;
}
//¾î´ðÅÍ Å¬·¡½º
class MyListAdapter extends BaseAdapter {
Context maincon;
LayoutInflater Inflater;
ArrayList<MyItem> arSrc;
int layout;
public MyListAdapter(Context context, int alayout, ArrayList<MyItem> aarSrc) {
maincon = context;
Inflater = (LayoutInflater)context.getSystemServic(Context.LAYOUT_INFLATER_SERVICE);
arSrc = aarSrc;
layout = alayout;
}
public int getCount() {
return arSrc.size();
}
public String getItem(int position) {
return arSrc.get(position).Name;
}
public long getItemId(int position) {
return position;
}
// °¢ Ç׸ñÀÇ ºä »ý¼º
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = Inflater.inflate(layout, parent, false);
}
ImageView img = (ImageView)convertView.findViewById(R.id.img);
img.setImageResource(arSrc.get(position).Icon);
TextView txt = (TextView)convertView.findViewById(R.id.text);
txt.setText(arSrc.get(position).Name);
return convertView;
}
}