ListView 실습
public class ListView1 extends Activity {
/** Called when the activity is first created. */
static final String[] fruits = new String[] {
"Apple", "Banana", "Cupcake", "Donut", "Eclair", "Froyo"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lv = (ListView)findViewById(R.id.list1);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, fruits));
lv.setOnItemClickListener (listener);
}
ListView.OnItemClickListener listener =
new ListView.OnItemClickListener () {
public void onItemClick(AdapterView<?> list,
View view, int position, long id) {
String s = "Select Item = " + fruits[position];
Toast.makeText(getBaseContext(), s, Toast.LENGTH_SHORT)
.show();
}
};
}
'2013년 2학기 > 안드로이드프로그래밍응용' 카테고리의 다른 글
View Pager 실습 예제 (0) | 2013.11.13 |
---|---|
Dialog 실습 (0) | 2013.10.30 |
안드로이드 개발 환경 설치 (0) | 2013.09.04 |