아,,몇시간째 안된다고 고민을 하고있는건지,,
제가 지금 리스트를 5개를 만들어서 한 액티비티에 붙였어요,
그리고 나서, 각각의 리스트는 inflate로 뷰에 넣어주어서,
받아온 값을 이용해 유동적으로 리스트를 형성해 주었고요,
제가 지금 하고싶은건, 각각의 리스트에 있는 아이템값들 즉 포지션 값들을 받아오고 싶은대,
왠지 모르게 포지션값들이 받아와지지 않네요;;;
각각의 리스트값들의 포지션값들을 받아오고 싶은대,
어떻게 하면 좋을까요??
setOnItemClickListener이걸 사용해서는 안되는건가요??
ㅠ.ㅠ 답변주세요ㅠ.ㅠㅋㅋ
public class SeeStatus extends Activity{
private ArrayList<Status> cateList; //노트리스트생성
private LinearLayout wireless;
private LinearLayout where;
private LinearLayout area;
private LinearLayout motion;
private LinearLayout phone;
private ListView list_wireless;
private ListView list_where;
private ListView list_area;
private ListView list_motion;
private ListView list_phone;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.see_status);
cateList = new ArrayList<Status>();
cateList = Context_Reg.cateList;
wireless = (LinearLayout)findViewById(R.see_status.wireless);
where = (LinearLayout)findViewById(R.see_status.where);
area = (LinearLayout)findViewById(R.see_status.area);
motion = (LinearLayout)findViewById(R.see_status.motion);
phone = (LinearLayout)findViewById(R.see_status.phone);
list_wireless = (ListView)findViewById(R.id.android_list_1);
list_where = (ListView)findViewById(R.id.android_list_2);
list_area = (ListView)findViewById(R.id.android_list_3);
list_motion = (ListView)findViewById(R.id.android_list_4);
list_phone = (ListView)findViewById(R.id.android_list_5);
for(int i=0 ;i< cateList.size();i++){
System.out.println("size:"+cateList.size());
System.out.println("getType:"+cateList.get(i).getType());
System.out.println("getInfo:"+cateList.get(i).getInfo());
System.out.println("getValue:"+cateList.get(i).getValue());
View v = null ;
ImageView img ;
TextView state;
TextView value;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
switch(cateList.get(i).getType()){
case 0:
v = vi.inflate(R.layout.status_wireless, null);
img = (ImageView) v.findViewById(R.status.status_img);
state = (TextView) v.findViewById(R.status.status_text);
value = (TextView) v.findViewById(R.status.status_value);
img.setImageResource(R.drawable.stat_sys_tether_wifi);
state.setText(cateList.get(i).getInfo());
value.setText(cateList.get(i).getValue());
wireless.addView(v);
break;
case 1:
v = vi.inflate(R.layout.status_where, null);
img = (ImageView) v.findViewById(R.status.status_img);
state = (TextView) v.findViewById(R.status.status_text);
value = (TextView) v.findViewById(R.status.status_value);
value.setText(cateList.get(i).getValue());
img.setImageResource(R.drawable.ic_menu_mylocation);
state.setText(cateList.get(i).getInfo());
where.addView(v);
break;
case 2:
v = vi.inflate(R.layout.status_area, null);
img = (ImageView) v.findViewById(R.status.status_img);
state = (TextView) v.findViewById(R.status.status_text);
value = (TextView) v.findViewById(R.status.status_value);
value.setText(cateList.get(i).getValue());
img.setImageResource(R.drawable.ic_menu_mylocation);
state.setText(cateList.get(i).getInfo());
area.addView(v);
break;
case 3:
v = vi.inflate(R.layout.status_motion, null);
img = (ImageView) v.findViewById(R.status.status_img);
state = (TextView) v.findViewById(R.status.status_text);
value = (TextView) v.findViewById(R.status.status_value);
value.setText(cateList.get(i).getValue());
img.setImageResource(R.drawable.ic_menu_mylocation);
state.setText(cateList.get(i).getInfo());
motion.addView(v);
break;
case 4:
v = vi.inflate(R.layout.status_phone, null);
img = (ImageView) v.findViewById(R.status.status_img);
state = (TextView) v.findViewById(R.status.status_text);
value = (TextView) v.findViewById(R.status.status_value);
value.setText(cateList.get(i).getValue());
img.setImageResource(R.drawable.ic_menu_mylocation);
state.setText(cateList.get(i).getInfo());
phone.addView(v);
break;
}
}
list_wireless.setClickable(true);
list_where.setClickable(true);
list_area.setClickable(true);
list_motion.setClickable(true);
list_phone.setClickable(true);
list_wireless.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
System.out.println("position1"+position);
}
});
list_where.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
System.out.println("position2"+position);
}
});
list_area.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
System.out.println("position3"+position);
}
});
list_motion.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
System.out.println("position4"+position);
}
});
list_phone.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
System.out.println("position5"+position);
}
});
}
}
즉 click이벤트에 응답자체를 안한다는건데... 현재 소스만 봐서는 리스트안의 아이템들이 하나라도 inflate가 제대로 되는지 이해하기가 어렵네요..
굳이 이방식대로 코딩하신다면 새로 프로젝트를 구성하셔서 listview와 layout하나씩만 이용하시고 select case가 아닌 cateList의 값들을 그냥 선언한 list에 직접 넣으시고 리스너 등록하셔서 테스트해보세요.. 디버깅으로 메쏘드 라인 하나하나 잡으시면서 변수값 확인하시면 해결하기가 좀 더 수월할겁니다.
밑에 리스너 등록 부분에 breakpoint 잡으시고 에뮬에서 클릭할때 제어가 넘어가는지 확인해보세요. 코드짜시는 스타일이 저랑 많이 달라서 좀 헷갈리긴하는데 흠... 저같은경우는 adapter안에서 각 리스트값을 받아오거든요.