2011. 8. 29. 13:08

안드로이드, XML없이 ListActivity로 만드는 리스트 뷰(ListView)


package kr.test;
import java.util.ArrayList;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListTestAdvancedActivity extends ListActivity { 
 private ArrayList<CharSequence> foodList = new ArrayList<CharSequence>() ; 
 private ArrayAdapter<CharSequence> arrayAdapter ;
 
    /-* Called when the activity is first created. *-
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
  
        foodList.add("김치찌개") ;
        foodList.add("된장찌개") ;
        foodList.add("육개장") ;
        foodList.add("햄버거") ;
        foodList.add("간짜장 라이~") ;
        foodList.add("난 짬뽕") ;
        foodList.add("탕슉") ;
        foodList.add("군만두는 싸~비스") ;
        
        arrayAdapter = new ArrayAdapter<CharSequence>(this,
          android.R.layout.simple_list_item_single_choice, foodList) ;
    
        this.setListAdapter(arrayAdapter) ;
        this.getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE) ;
    }
}