importjava.util.ArrayList;
importandroid.app.Activity;
importandroid.content.Context;
importandroid.os.Bundle;
importandroid.util.AttributeSet;
importandroid.util.Log;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.view.View.OnClickListener;
importandroid.widget.ArrayAdapter;
importandroid.widget.CheckBox;
importandroid.widget.Checkable;
importandroid.widget.ImageView;
importandroid.widget.LinearLayout;
importandroid.widget.ListView;
importandroid.widget.TextView;
importcom.sec.android.touchwiz.samples.R;
publicclassListLayoutSample3XmlextendsActivity{
ListViewmListView;
privatefinalStringLOG_TAG_LISTLAYOUTSAMPLE3="ListLayoutSample3Xml";
/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.listlayoutsample3xml_main);
mListView=(ListView)findViewById(R.id.contactCheckList);
//[09.10.23]ListView?choiceMode?CHOICE_MODE_MULTIPLE?????
//???item?check??????
//[E]SetListView'schoiceModetoCHOICE_MODE_MULTIPLEformulticheck.
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
ArrayList<ContactItem>list=newArrayList<ContactItem>();
for(inti=0;i<mName.length;i++){
ContactItemcontact=newContactItem(mThumbs<wbr style="line-height:25px">,mName<wbr style="line-height:25px">);<br style="line-height:25px"> list.add(contact);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //ContactAdapter??<br style="line-height:25px"> ContactAdaptercAdapter=newContactAdapter(this,R.layout.listlayoutsample3xml_row,list);<br style="line-height:25px"> //ListView?ContactAdapter???<br style="line-height:25px"> mListView.setAdapter(cAdapter);<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *ContactItem????Thumbnaildata<br style="line-height:25px"> */<br style="line-height:25px"> privateInteger[]mThumbs={<br style="line-height:25px"> R.drawable.listlayoutsample3xml_1,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_2,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_3,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_4,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_5,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_seankingston,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_karina,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_jayz,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_madonna};<br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *ContactItem????FullNamedata<br style="line-height:25px"> */<br style="line-height:25px"> privateString[]mName=<br style="line-height:25px"> {<br style="line-height:25px"> "AnnaBay",<br style="line-height:25px"> "AgathaChristina",<br style="line-height:25px"> "AgnesGreen",<br style="line-height:25px"> "Mom",<br style="line-height:25px"> "July",<br style="line-height:25px"> "SeanKingston",<br style="line-height:25px"> "Karina",<br style="line-height:25px"> "Jay-Z",<br style="line-height:25px"> "Madonna"<br style="line-height:25px"> };<br style="line-height:25px"><br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *ListView?????Adapter.ArrayAdapter???????.<br style="line-height:25px"> *ContactItemtype?data??ArrayList????.<br style="line-height:25px"> */<br style="line-height:25px"> privateclassContactAdapterextendsArrayAdapter<ContactItem>{<br style="line-height:25px"><br style="line-height:25px"> privateArrayList<ContactItem>items;<br style="line-height:25px"><br style="line-height:25px"> publicContactAdapter(Contextcontext,inttextViewResourceId,ArrayList<ContactItem>items){<br style="line-height:25px"> super(context,textViewResourceId,items);<br style="line-height:25px"> this.items=items;<br style="line-height:25px"> }<br style="line-height:25px"> @Override<br style="line-height:25px"> publicViewgetView(intposition,ViewconvertView,ViewGroupparent){<br style="line-height:25px"> Viewv=convertView;<br style="line-height:25px"> if(v==null){<br style="line-height:25px"> LayoutInflatervi=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br style="line-height:25px"> v=vi.inflate(R.layout.listlayoutsample3xml_row,null);<br style="line-height:25px"> }<br style="line-height:25px"> ContactItemti=items.get(position);<br style="line-height:25px"> if(ti!=null){<br style="line-height:25px"> ImageViewthumbview=(ImageView)v.findViewById(R.id.photo1);<br style="line-height:25px"> TextViewnameview=(TextView)v.findViewById(R.id.text1);<br style="line-height:25px"> finalCheckBoxcheck=(CheckBox)v.findViewById(R.id.checkbox1);<br style="line-height:25px"><br style="line-height:25px"> if(thumbview!=null){<br style="line-height:25px"> thumbview.setImageResource(ti.getContactThumb());<br style="line-height:25px"> }<br style="line-height:25px"> if(nameview!=null){<br style="line-height:25px"> nameview.setText(ti.getFullName());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> finalintmyPosition=position;<br style="line-height:25px"> check.setOnClickListener(newOnClickListener(){<br style="line-height:25px"><br style="line-height:25px"> publicvoidonClick(Viewv){<br style="line-height:25px"> check.post(newRunnable(){<br style="line-height:25px"> publicvoidrun(){<br style="line-height:25px"> booleanfchecked=check.isChecked();<br style="line-height:25px"> onBtnCheckChanged(myPosition,fchecked);<br style="line-height:25px"> }<br style="line-height:25px"> });<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> });<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> returnv;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> privatevoidonBtnCheckChanged(intposition,booleancheck){<br style="line-height:25px"> Log.d(LOG_TAG_LISTLAYOUTSAMPLE3,"onBtnCheckChanged("+position+","+check+")");<br style="line-height:25px"> mListView.setItemChecked(position,check);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *@authorcooldawn.kim<br style="line-height:25px"> *<br style="line-height:25px"> *ContactItem<br style="line-height:25px"> */<br style="line-height:25px"> classContactItem{<br style="line-height:25px"> privateIntegermContactThumb;<br style="line-height:25px"> privateStringmFullName;<br style="line-height:25px"><br style="line-height:25px"> publicContactItem(Integerthumb,StringfullName)<br style="line-height:25px"> {<br style="line-height:25px"> this.mContactThumb=thumb;<br style="line-height:25px"> this.mFullName=fullName;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicIntegergetContactThumb(){<br style="line-height:25px"> returnmContactThumb;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetFullName(){<br style="line-height:25px"> returnmFullName;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }//classContactItem<br style="line-height:25px"><br style="line-height:25px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publicstaticclass</span><span style="color:#ff6600; line-height:25px">ItemView</span><span style="color:#3366ff; line-height:25px">extendsLinearLayoutimplementsCheckable{<br style="line-height:25px"><br style="line-height:25px"> publicItemView(Contextcontext,AttributeSetattrs){<br style="line-height:25px"> super(context,attrs);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicbooleanisChecked(){<br style="line-height:25px"> CheckBoxcheck=findCheckBox();<br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> returncheck.isChecked();<br style="line-height:25px"> }<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicvoidsetChecked(booleanchecked){<br style="line-height:25px"> Log.d("ItemView","setChecked("+checked+")");<br style="line-height:25px"> CheckBoxcheck=findCheckBox();<br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> check.setChecked(checked);<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicvoidtoggle(){<br style="line-height:25px"> CheckBoxcheck=findCheckBox();<br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> check.toggle();<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> privateCheckBoxfindCheckBox(){<br style="line-height:25px"> Viewcheck=findViewById(R.id.checkbox1);<br style="line-height:25px"> if(check!=null&&checkinstanceofCheckBox){<br style="line-height:25px"> return(CheckBox)check;<br style="line-height:25px"> }<br style="line-height:25px"> returnnull;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }</span><br style="line-height:25px"> }</wbr></wbr>
importandroid.app.Activity;
importandroid.content.Context;
importandroid.os.Bundle;
importandroid.util.AttributeSet;
importandroid.util.Log;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.view.View.OnClickListener;
importandroid.widget.ArrayAdapter;
importandroid.widget.CheckBox;
importandroid.widget.Checkable;
importandroid.widget.ImageView;
importandroid.widget.LinearLayout;
importandroid.widget.ListView;
importandroid.widget.TextView;
importcom.sec.android.touchwiz.samples.R;
publicclassListLayoutSample3XmlextendsActivity{
ListViewmListView;
privatefinalStringLOG_TAG_LISTLAYOUTSAMPLE3="ListLayoutSample3Xml";
/**Calledwhentheactivityisfirstcreated.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.listlayoutsample3xml_main);
mListView=(ListView)findViewById(R.id.contactCheckList);
//[09.10.23]ListView?choiceMode?CHOICE_MODE_MULTIPLE?????
//???item?check??????
//[E]SetListView'schoiceModetoCHOICE_MODE_MULTIPLEformulticheck.
mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
ArrayList<ContactItem>list=newArrayList<ContactItem>();
for(inti=0;i<mName.length;i++){
ContactItemcontact=newContactItem(mThumbs<wbr style="line-height:25px">,mName<wbr style="line-height:25px">);<br style="line-height:25px"> list.add(contact);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> //ContactAdapter??<br style="line-height:25px"> ContactAdaptercAdapter=newContactAdapter(this,R.layout.listlayoutsample3xml_row,list);<br style="line-height:25px"> //ListView?ContactAdapter???<br style="line-height:25px"> mListView.setAdapter(cAdapter);<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *ContactItem????Thumbnaildata<br style="line-height:25px"> */<br style="line-height:25px"> privateInteger[]mThumbs={<br style="line-height:25px"> R.drawable.listlayoutsample3xml_1,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_2,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_3,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_4,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_5,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_seankingston,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_karina,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_jayz,<br style="line-height:25px"> R.drawable.listlayoutsample3xml_madonna};<br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *ContactItem????FullNamedata<br style="line-height:25px"> */<br style="line-height:25px"> privateString[]mName=<br style="line-height:25px"> {<br style="line-height:25px"> "AnnaBay",<br style="line-height:25px"> "AgathaChristina",<br style="line-height:25px"> "AgnesGreen",<br style="line-height:25px"> "Mom",<br style="line-height:25px"> "July",<br style="line-height:25px"> "SeanKingston",<br style="line-height:25px"> "Karina",<br style="line-height:25px"> "Jay-Z",<br style="line-height:25px"> "Madonna"<br style="line-height:25px"> };<br style="line-height:25px"><br style="line-height:25px"><br style="line-height:25px"> /*<br style="line-height:25px"> *ListView?????Adapter.ArrayAdapter???????.<br style="line-height:25px"> *ContactItemtype?data??ArrayList????.<br style="line-height:25px"> */<br style="line-height:25px"> privateclassContactAdapterextendsArrayAdapter<ContactItem>{<br style="line-height:25px"><br style="line-height:25px"> privateArrayList<ContactItem>items;<br style="line-height:25px"><br style="line-height:25px"> publicContactAdapter(Contextcontext,inttextViewResourceId,ArrayList<ContactItem>items){<br style="line-height:25px"> super(context,textViewResourceId,items);<br style="line-height:25px"> this.items=items;<br style="line-height:25px"> }<br style="line-height:25px"> @Override<br style="line-height:25px"> publicViewgetView(intposition,ViewconvertView,ViewGroupparent){<br style="line-height:25px"> Viewv=convertView;<br style="line-height:25px"> if(v==null){<br style="line-height:25px"> LayoutInflatervi=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);<br style="line-height:25px"> v=vi.inflate(R.layout.listlayoutsample3xml_row,null);<br style="line-height:25px"> }<br style="line-height:25px"> ContactItemti=items.get(position);<br style="line-height:25px"> if(ti!=null){<br style="line-height:25px"> ImageViewthumbview=(ImageView)v.findViewById(R.id.photo1);<br style="line-height:25px"> TextViewnameview=(TextView)v.findViewById(R.id.text1);<br style="line-height:25px"> finalCheckBoxcheck=(CheckBox)v.findViewById(R.id.checkbox1);<br style="line-height:25px"><br style="line-height:25px"> if(thumbview!=null){<br style="line-height:25px"> thumbview.setImageResource(ti.getContactThumb());<br style="line-height:25px"> }<br style="line-height:25px"> if(nameview!=null){<br style="line-height:25px"> nameview.setText(ti.getFullName());<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> finalintmyPosition=position;<br style="line-height:25px"> check.setOnClickListener(newOnClickListener(){<br style="line-height:25px"><br style="line-height:25px"> publicvoidonClick(Viewv){<br style="line-height:25px"> check.post(newRunnable(){<br style="line-height:25px"> publicvoidrun(){<br style="line-height:25px"> booleanfchecked=check.isChecked();<br style="line-height:25px"> onBtnCheckChanged(myPosition,fchecked);<br style="line-height:25px"> }<br style="line-height:25px"> });<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> });<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"> returnv;<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> privatevoidonBtnCheckChanged(intposition,booleancheck){<br style="line-height:25px"> Log.d(LOG_TAG_LISTLAYOUTSAMPLE3,"onBtnCheckChanged("+position+","+check+")");<br style="line-height:25px"> mListView.setItemChecked(position,check);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> /**<br style="line-height:25px"> *@authorcooldawn.kim<br style="line-height:25px"> *<br style="line-height:25px"> *ContactItem<br style="line-height:25px"> */<br style="line-height:25px"> classContactItem{<br style="line-height:25px"> privateIntegermContactThumb;<br style="line-height:25px"> privateStringmFullName;<br style="line-height:25px"><br style="line-height:25px"> publicContactItem(Integerthumb,StringfullName)<br style="line-height:25px"> {<br style="line-height:25px"> this.mContactThumb=thumb;<br style="line-height:25px"> this.mFullName=fullName;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicIntegergetContactThumb(){<br style="line-height:25px"> returnmContactThumb;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicStringgetFullName(){<br style="line-height:25px"> returnmFullName;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }//classContactItem<br style="line-height:25px"><br style="line-height:25px"><span style="color:#3366ff; line-height:25px"></span><span style="color:#993300; line-height:25px">publicstaticclass</span><span style="color:#ff6600; line-height:25px">ItemView</span><span style="color:#3366ff; line-height:25px">extendsLinearLayoutimplementsCheckable{<br style="line-height:25px"><br style="line-height:25px"> publicItemView(Contextcontext,AttributeSetattrs){<br style="line-height:25px"> super(context,attrs);<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicbooleanisChecked(){<br style="line-height:25px"> CheckBoxcheck=findCheckBox();<br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> returncheck.isChecked();<br style="line-height:25px"> }<br style="line-height:25px"> returnfalse;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicvoidsetChecked(booleanchecked){<br style="line-height:25px"> Log.d("ItemView","setChecked("+checked+")");<br style="line-height:25px"> CheckBoxcheck=findCheckBox();<br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> check.setChecked(checked);<br style="line-height:25px"> }<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> publicvoidtoggle(){<br style="line-height:25px"> CheckBoxcheck=findCheckBox();<br style="line-height:25px"> if(check!=null){<br style="line-height:25px"> check.toggle();<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> privateCheckBoxfindCheckBox(){<br style="line-height:25px"> Viewcheck=findViewById(R.id.checkbox1);<br style="line-height:25px"> if(check!=null&&checkinstanceofCheckBox){<br style="line-height:25px"> return(CheckBox)check;<br style="line-height:25px"> }<br style="line-height:25px"> returnnull;<br style="line-height:25px"> }<br style="line-height:25px"><br style="line-height:25px"> }</span><br style="line-height:25px"> }</wbr></wbr>