안드로이드 개발 질문/답변
(글 수 45,052)
기본 Activity 를 상속받았고, 데이터베이스에 데이터를 저장해 놓았습니다.
커서를 이용해서 해당 데이터를 모두 읽어와 리스트에 뿌려주는건데요
onItemClickListener 가 동작을 하지 않네요;;
왜 이런건지....그리고 아래쪽에 newView 부분에서는 각 ListItem 마다 각기 다른 이미지를 넣어주는건데요
1번에서 7번까지는 잘 들어가다가 8번부터는 제대로 들어가긴 하는데 1번 이미지가 8번과 동일하게 변해버립니다.
어떻게 해결해야 하는지 조언 부탁드립니다.
c = mRecent_Save.getAllNotes();
startManagingCursor(c);
l = (ListView)findViewById(R.id.db_list);
l.setAdapter(new DbAdapter(this, c));
l.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.d("onitemclick", Integer.toString(arg2));
}
});
private class DbAdapter extends CursorAdapter implements ListAdapter
{
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
private Long id;
private RecentSave mRecentSave;
public DbAdapter(Context context, Cursor cursor)
{
super(context, cursor, true);
mInflater = LayoutInflater.from(context);
mContext = context;
mRecentSave = new RecentSave(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
TextView t1 = (TextView)view.findViewById(R.id.new_title);
TextView t2 = (TextView)view.findViewById(R.id.new_content);
TextView t3 = (TextView)view.findViewById(R.id.new_file);
TextView t4 = (TextView)view.findViewById(R.id.new_time);
t1.setFocusable(false);
t2.setFocusable(false);
t3.setFocusable(false);
t4.setFocusable(false);
t1.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_TITLE)));
t2.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_BODY)));
t3.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_FILE)));
t4.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_TIME)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
final View view = mInflater.inflate(R.layout.newlist,
parent, false);
bindView(view, context, cursor);
ImageView[] iv = new ImageView[7];
iv[0] = (ImageView)view.findViewById(R.id.ImageView31);
iv[1] = (ImageView)view.findViewById(R.id.ImageView32);
iv[2] = (ImageView)view.findViewById(R.id.ImageView33);
iv[3] = (ImageView)view.findViewById(R.id.ImageView34);
iv[4] = (ImageView)view.findViewById(R.id.ImageView35);
iv[5] = (ImageView)view.findViewById(R.id.ImageView36);
iv[6] = (ImageView)view.findViewById(R.id.ImageView37);
String temp = cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_ICON));
Log.d("DBDBDB", (String)cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_BODY)));
Log.d("DBDBDB", (String)cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_ICON)));
int[] icon = {0, 0, 0, 0, 0, 0, 0};
for(int i = 0; i < icon.length; i++)
{
icon[i] =
Integer.parseInt(temp.substring(i, i + 1));
if(icon[i] == 1)
{
iv[i].setImageBitmap(BlogChoice.blogiconList.get(i));
}
}
return view;
}
커서를 이용해서 해당 데이터를 모두 읽어와 리스트에 뿌려주는건데요
onItemClickListener 가 동작을 하지 않네요;;
왜 이런건지....그리고 아래쪽에 newView 부분에서는 각 ListItem 마다 각기 다른 이미지를 넣어주는건데요
1번에서 7번까지는 잘 들어가다가 8번부터는 제대로 들어가긴 하는데 1번 이미지가 8번과 동일하게 변해버립니다.
어떻게 해결해야 하는지 조언 부탁드립니다.
c = mRecent_Save.getAllNotes();
startManagingCursor(c);
l = (ListView)findViewById(R.id.db_list);
l.setAdapter(new DbAdapter(this, c));
l.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.d("onitemclick", Integer.toString(arg2));
}
});
private class DbAdapter extends CursorAdapter implements ListAdapter
{
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
private Long id;
private RecentSave mRecentSave;
public DbAdapter(Context context, Cursor cursor)
{
super(context, cursor, true);
mInflater = LayoutInflater.from(context);
mContext = context;
mRecentSave = new RecentSave(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
TextView t1 = (TextView)view.findViewById(R.id.new_title);
TextView t2 = (TextView)view.findViewById(R.id.new_content);
TextView t3 = (TextView)view.findViewById(R.id.new_file);
TextView t4 = (TextView)view.findViewById(R.id.new_time);
t1.setFocusable(false);
t2.setFocusable(false);
t3.setFocusable(false);
t4.setFocusable(false);
t1.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_TITLE)));
t2.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_BODY)));
t3.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_FILE)));
t4.setText(cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_TIME)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
final View view = mInflater.inflate(R.layout.newlist,
parent, false);
bindView(view, context, cursor);
ImageView[] iv = new ImageView[7];
iv[0] = (ImageView)view.findViewById(R.id.ImageView31);
iv[1] = (ImageView)view.findViewById(R.id.ImageView32);
iv[2] = (ImageView)view.findViewById(R.id.ImageView33);
iv[3] = (ImageView)view.findViewById(R.id.ImageView34);
iv[4] = (ImageView)view.findViewById(R.id.ImageView35);
iv[5] = (ImageView)view.findViewById(R.id.ImageView36);
iv[6] = (ImageView)view.findViewById(R.id.ImageView37);
String temp = cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_ICON));
Log.d("DBDBDB", (String)cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_BODY)));
Log.d("DBDBDB", (String)cursor.getString(
cursor.getColumnIndex(RecentSave.KEY_ICON)));
int[] icon = {0, 0, 0, 0, 0, 0, 0};
for(int i = 0; i < icon.length; i++)
{
icon[i] =
Integer.parseInt(temp.substring(i, i + 1));
if(icon[i] == 1)
{
iv[i].setImageBitmap(BlogChoice.blogiconList.get(i));
}
}
return view;
}
2010.02.01 15:50:42
회색님 감사합니다. 말씀대로 BindView 부분에 놓았더니 반복되는 현상은 사라졌네요.
그런데 BlogChoice class 에 ArrayList<Bitmap> 을 통하여 값이 1 일 경우에만 그림을 받게 해놨는데요
로그로 살펴보면 원하는 이미지만 1로 변경이 되어 데이터베이스에 저장이 되고 잘 불러와 지는것을 볼 수 있었습니다.
하지만 List 를 살펴보면 이미지가 전체가 출력이 되거나 상관없는 이미지도 출력되는 현상이 일어나네요.
BindView 부분에서 각각의 ListItem 에 내용과 그림을 추가하였는데, 왜 이런 현상이 일어나는지....
그리고 위에서 ListView 에 대한 OnItemClickListener 는 왜 동작을 안하는지에 대한 의견도 좀 부탁 드리겠습니다.
그런데 BlogChoice class 에 ArrayList<Bitmap> 을 통하여 값이 1 일 경우에만 그림을 받게 해놨는데요
로그로 살펴보면 원하는 이미지만 1로 변경이 되어 데이터베이스에 저장이 되고 잘 불러와 지는것을 볼 수 있었습니다.
하지만 List 를 살펴보면 이미지가 전체가 출력이 되거나 상관없는 이미지도 출력되는 현상이 일어나네요.
BindView 부분에서 각각의 ListItem 에 내용과 그림을 추가하였는데, 왜 이런 현상이 일어나는지....
그리고 위에서 ListView 에 대한 OnItemClickListener 는 왜 동작을 안하는지에 대한 의견도 좀 부탁 드리겠습니다.