public class DataBWT2 extends Activity 
implements AdapterView.OnItemClickListener {
//Model Case 1 
    private static final String ITEMS[] = 
    {
    "동백꽃", "개나리", "진달래", "철쭉", "백합", "튜울립", 
    "장미", "봉선화", "무궁화", "벗꽃", "살구꽃", "복숭아꽃", 
    "할미꽃", "에델바이스", "안개꽃", "카네이션", "들국화", 
    "가나다", "가나라", "가다라", "가지마", "가나다라", 
    "cat", "catch", "cast", "case", "casting", "cap"
    };
    private ListView lv; //View 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        lv = (ListView)findViewById(R.id.ListView01);
        android.util.Log.i("lv", ""+lv);
        
        //m1(); //Model - Array 
        //m2(); //Model - List
        m3(); //Model - Xml 
    }
    //4. 자신 
    public void onItemClick (
AdapterView<?> parent, View view, int position, long id){
ArrayAdapter<String> aa = (ArrayAdapter<String>)parent.getAdapter();
Toast.makeText(this, 
"선택(4) : " + aa.getItem(position), 0).show();
}
    void m1(){
    ArrayAdapter<String> aa = new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, 
               ITEMS);
        lv.setAdapter(aa);
        /*//1. 익명(무명) 내부 
        AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
    public void onItemClick (
    AdapterView<?> parent, View view, int position, long id){
    ArrayAdapter<String> aa = (ArrayAdapter<String>)parent.getAdapter();
   
    Toast.makeText(DataBWT2.this, 
    "선택(1) : " + aa.getItem(position), 0).show();
    }
        };*/
        /*//2. 유명 내부 
        class A implements AdapterView.OnItemClickListener {
        public void onItemClick (
    AdapterView<?> parent, View view, int position, long id){
    ArrayAdapter<String> aa = (ArrayAdapter<String>)parent.getAdapter();
   
    Toast.makeText(DataBWT2.this, 
    "선택(2) : " + aa.getItem(position), 0).show();
    }
        }*/
        
        lv.setOnItemClickListener(this);
    }
    
    ArrayAdapter<String> aa;
    void m2(){
    List list = new Vector<String>();
    for(String item : ITEMS) list.add(item);
    aa = new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, list);
        lv.setAdapter(aa);
        lv.setOnItemClickListener(this);
    }
    ArrayAdapter adapter;
    void m3(){
    adapter = ArrayAdapter.createFromResource(
    this, R.array.animals, 
    android.R.layout.simple_list_item_1);
    lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick (
    AdapterView<?> parent, View view, int position, long id){
    //ArrayAdapter adapter = (ArrayAdapter)parent.getAdapter();
   
    Toast.makeText(DataBWT2.this, 
    "선택(xml) : " + adapter.getItem(position), 0).show();
    }
});
    }
}
/* 3. 제3클 
class B implements AdapterView.OnItemClickListener {
DataBWT2 d;
B(DataBWT2 d){
this.d = d;
}
public void onItemClick (
AdapterView<?> parent, View view, int position, long id){
ArrayAdapter<String> aa = (ArrayAdapter<String>)parent.getAdapter();
Toast.makeText(d, 
"선택(3) : " + aa.getItem(position), 0).show();
}
}*/

'스마트폰 > 안드로이드' 카테고리의 다른 글

데이터 바인딩4 공부  (0) 2011.05.13
데이터 바인딩3 공부  (0) 2011.05.13
데이터 바인딩1 공부  (0) 2011.05.13
anim2(애니메이션) 공부  (0) 2011.05.13
TabHost 공부.  (0) 2011.05.13

+ Recent posts