<ListView android:id="@+id/resultlv" android:layout_width="match_parent" android:layout_height="366dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginBottom="30dp" android:layout_marginTop="115dp" android:choiceMode="singleChoice" />
private ArrayList items = null;
private ArrayAdapter adapter = null;
// 빈 데이터 리스트 생성.
items = new ArrayList() ;
// ArrayAdapter 생성. 아이템 View를 선택(single choice)가능하도록 만듦.adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_single_choice, items) ;
listview.setAdapter(adapter) ;
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override public void onItemClick(AdapterView parent, View v, int position, long id) {
// get TextView's Text. String strText = (String) parent.getItemAtPosition(position) ;
Toast.makeText(getApplicationContext(), strText, Toast.LENGTH_LONG).show();
}
}) ;
// 아이템 추가.items.add(strText);
//items.add(strText + Integer.toString(count + 1));
// listview 갱신adapter.notifyDataSetChanged();
//아이템 전체 삭제items.clear();
// listview 갱신adapter.notifyDataSetChanged();
출처: http://developmentlee.tistory.com/91?category=796972 [developmentlee]
댓글
댓글 쓰기