안드로이드 개발 질문/답변
(글 수 45,052)
private OnItemLongClickListener longClickListener = new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
showAlertDialog();
return false;
}
};private void showAlertDialog() {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout scanLayout = (LinearLayout) vi.inflate(R.layout.scandialog, null);
final EditText et_num = (EditText) scanLayout.findViewById(R.id.et_num);
String bc_num;
TextView tv_num = (TextView)findViewById(R.id.tv_num);
bc_num = ((TextView)tv_num.findViewById(R.id.tv_num)).getText().toString();
et_num.setText(bc_num);
}
커스텀 리스트뷰의 아이템 클릭시에 다이얼로그창을 띄우고
다이얼로그에서는 클릭된 리스트의 텍스트뷰 데이터를 출력하려고하는데
선택된 리스트뷰의 데이터를 가져오긴 가져오는데
어디를 클릭하던간에 첫번째줄의 데이터만 출력되네요...
조언부탁드립니다.




리스트 뷰에 들어가는 데이터 리스트를 누른 포지션에 맞춰 불러오면 됩니다.
et_num.setText( ); 할때 데이터를 누른 위치값에 알맞는 걸로 넣어줘야 합니다.
private OnItemLongClickListener longClickListener = new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
showAlertDialog();
return false;
}
};
보시면 arg0 과 position 이 핵심 입니다.
arg0.getItemAtPosition(position) 하시면 해당 위치의 데이터를 불러올수 있습니다.
따라서!
private OnItemLongClickListener longClickListener = new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
showAlertDialog((String)arg0.getItemAtPosition(position));
return false;
}
};
private void showAlertDialog(String data) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout scanLayout = (LinearLayout) vi.inflate(R.layout.scandialog, null);
final EditText et_num = (EditText) scanLayout.findViewById(R.id.et_num);
et_num.setText(data);
}
이처럼 구현 하면 되지 않을까 하는데,
만일 안된다면 Adapter 를 상속 받은 클래스에서
getItem() 메서드의 리턴값을 데이터담고 있는 리스트 변수에서 position 값으로 불러오도록 설정해야합니다.
데이터 리스트 변수가 String[] mData 라면..
getItem(int position){
return mData(position);
}
이런식으로요 :ㅁ
복잡허네요~