[ListView #1] ListView하나만 보여주기.

Posted by [하늘이]
2010. 11. 25. 15:52 IT/Android[안드로이드]
반응형


main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <ListView
  android:id="@+id/ListView01" android:layout_width="wrap_content"
  android:layout_height="wrap_content">
 </ListView>
</LinearLayout>

 


Source 


public class Test_Class extends Activity {
    /** Called when the activity is first created. */
 private ListView mListView;
 private ArrayList<String> mArrayList;
 private ArrayAdapter<String> mArrayAdpter;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       

        mListView = (ListView)findViewById(R.id.ListView01); //ListView 가져오기
        
        mArrayList = new ArrayList<String>(); //List 저장할 array

        //Adapter 생성
        mArrayAdpter = new ArrayAdapter<String>(this,
              android.R.layout.simple_list_item_1, mArrayList);
       
        mListView.setAdapter(mArrayAdpter);//List에 adapter등록
    }

 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();

  //화면에 보여줄 내용 저장.
  mArrayList.add("List 1");
  mArrayList.add("List 2");
  mArrayList.add("List 3");
  
 }
   
}

코맨트 외에 특별히 설명이 필요 없어 보이네요.



반응형