[안드로이드]리스트뷰 , [Android]ListView

2013. 1. 29. 11:18카테고리 없음



반응형

 

package com.example.ggari_listview;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {
	ArrayList<String> fruit;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		fruit = new ArrayList<String>();
		fruit.add("사과");
		fruit.add("딸기");
		fruit.add("배");
		fruit.add("수박");

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

		setListAdapter(Adapter);
	}

	public void onListItemClick(ListView list, View view, int position, long id) {
		Toast.makeText(MainActivity.this, "과일 이름 = " + fruit.get(position), 1).show();
	}
}
반응형