ListActivity를 상속받아서 진행할 수 있다.
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
String[] fruits =
{"사과","딸기","바나나","포도","멜론","키위","오렌지", "아보카도", "레몬", "체리", "망고"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, fruits);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String item = (String) getListAdapter().getItem(position);
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show();
}
}
'PROGRAM > Android' 카테고리의 다른 글
Fragment 예제 (0) | 2020.05.08 |
---|---|
ListView 아이템 추가,수정,삭제 (0) | 2020.05.01 |
ListView 추가하기 - 01 (0) | 2020.04.30 |
Android - listview (0) | 2020.04.28 |
OptionMenu (0) | 2020.04.25 |