본문 바로가기

Android

항목 뷰 - ListActivity

package com.example.listactivityex01;

 

import java.util.ArrayList;

 

 

import android.os.Bundle;

import android.app.Activity;

import android.app.ListActivity;

import android.view.Menu;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.Toast;

 

public class MainActivity extends ListActivity {

 

     @Override

     protected void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);

           //setContentView(R.layout.activity_main);

    

           ArrayList<String> list = new ArrayList<String>();

           list.add("김유신");

           list.add("이순신");

           list.add("을지문덕");

          

           ArrayAdapter<String> adapter

           = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,list);

          

           setListAdapter(adapter);

          

     }

    

    

 

     @Override

     protected void onListItemClick(ListView l, View v, int position, long id) {

           // TODO Auto-generated method stub

           String msg = "선택된 아이템 : " + position;

           Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();

     }

 

 

 

     @Override

     public boolean onCreateOptionsMenu(Menu menu) {

           // Inflate the menu; this adds items to the action bar if it is present.

           getMenuInflater().inflate(R.menu.main, menu);

           return true;

     }

 

}

 



'Android' 카테고리의 다른 글

어댑터 뷰 - 스피너  (0) 2013.04.01
항목 뷰 - 오버스크롤(OverScroll)  (0) 2013.04.01
항목 뷰 - 확장리스트뷰  (0) 2013.04.01
항목 뷰 - 커스텀 뷰  (0) 2013.04.01
리스트뷰 - 항목 추가,삭제하기 (multiplechoice)  (0) 2013.04.01