여기 데이터베이스에서 그림 경로가 저장됩니다. 그래서 나는 경로의 도움으로 gridview
에있는 이미지를 보여주고 있습니다. 그러나 아래 코드에서 볼 수 있듯이 을 asynctask
에로드하고 있습니다. 문제는 처음으로 모든 이미지가로드 될 때까지 시간이 걸리는 것이 좋습니다.simplecursoradapter에 대한 지연로드 구현
그러나 사용자가 데이터베이스에 또 하나의 그림을 추가하는 경우, 다시 나는 또한 추가 된 사진을 볼 수 있도록 onResume()에 asynctask
을 유지 모든 이미지를로드하는 데 많은 시간이 걸립니다. 사용자가 각 사진을 추가 할 때도 마찬가지입니다. 누군가가 다시 모든 사진을로드하지 않고도 gridview에서 마지막으로 추가 한 그림을 볼 수있는 간단한 방법을 제안 할 수 있습니까? 아니면 적어도 가능하다면 현재 cursoradapter에 게으른 어댑터를 구현하는 데 도움이 될 수 있습니까?
public class ImagesScreen extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.images_screen);
gridView = (GridView)findViewById(R.id.gridView1);
String[] from = new String[] { Reminders.MOM_PATHS };
int[] to = new int[] {};
dbCon = new SQLiteConnectClass(ImagesScreen.this);
imageCursorAdapter = new ImageCursorAdapter(ImagesScreen.this, R.layout.griditem, null, from, to);
gridView.setAdapter(imageCursorAdapter);
}
protected void onResume() {
super.onResume();
new GetImages().execute((Object[]) null);
}
private class GetImages extends AsyncTask<Object, Object, Cursor> {
@Override
protected Cursor doInBackground(Object... params) {
return dbCon.getAllImages();
}
@Override
protected void onPostExecute(Cursor result) {
imageAdapter.changeCursor(result);
}
public void addpictures(View view){
// code for adding picture paths to the database by transferring to another activity.
}
}
CustomAdapter 클래스 :
public class ImageCursorAdapter extends SimpleCursorAdapter{
private int layout;
private LayoutInflater mLayoutInflater;
private Context mContext;
public ImageAdapter(Context context, int layout, Cursor c,String[] from, int[] to) {
super(context, layout, c, from, to,0);
this.layout = layout;
mLayoutInflater=LayoutInflater.from(context);
mContext = context;
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mLayoutInflater.inflate(layout, parent, false);
return v;
}
public void bindView(final View v, final Context context, Cursor c) {
final int id = c.getInt(c.getColumnIndex("id"));
final String imagepath = c.getString(c.getColumnIndex("paths"));
ImageView imageview = (ImageView)v.findViewById(R.id.imageView1);
File imgFile = new File(imagepath);
if(imgFile.exists()){
Bitmap imageBitmap = decodeFile(imgFile);
imageview.setImageBitmap(imageBitmap);
}
}
}
이 예제를보십시오 http://stackoverflow.com/a/3068012/964741 –
왜 커서 어댑터 대신 기본 어댑터를 사용할 수 없습니다. – Senthil
@RajaReddyPolamReddy 간단한 어댑터가 아닌 내 cursror adpater에서 구현하는 방법에 대한 도움을받을 수 있습니까? – Apparatus