私はSDカードから画像をロードするこのグリッドビューを持っています....問題は、スクロールがまったくスムーズではなく、何が問題なのかわかりません....誰かが私を助けてくれますか??
private Cursor cursor;
private int columnIndex;
private GridView gridView;
ProgressDialog pd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gridView = (GridView) findViewById(R.id.gridview);
new LoadImages().execute();
/**
* Adapter for our image files.
*/
public class ImageAdapter extends BaseAdapter {
private Context context;
public ImageAdapter(Context localContext) {
context = localContext;
}
public int getCount() {
return cursor.getCount();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView picturesView;
if (convertView == null) {
picturesView = new ImageView(context);
picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
picturesView.setPadding(5, 5, 5, 5);
picturesView.setLayoutParams(new GridView.LayoutParams(80, 80));
}
else {
picturesView = (ImageView)convertView;
}
// Move cursor to current position
cursor.moveToPosition(position);
// Get the current value for the requested column
int imageID = cursor.getInt(columnIndex);
// Set the content of the image
picturesView.setImageBitmap(MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
imageID, MediaStore.Images.Thumbnails.MINI_KIND, null));
return picturesView;
}
}
この関数がバックグラウンド タスクとしてどのように機能するかわかりません!!!! それはちょうど動作します!! 洞察はありますか?
private void LoadImagesFromSDCard(){
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); //to update the database or rescan the database to get the captured image
//delay given for the sdcard to reload as per the above statement
try {
Thread.sleep(300L);
}
catch (Exception e) {}
// Set up an array of the Thumbnail Image ID column we want
String[] projection = {MediaStore.Images.Media._ID};
// Create the cursor pointing to the SDCard
cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
projection, // Which columns to return
null, // Return all rows
null,
MediaStore.Images.Media._ID);
// Get the column index of the Media Image ID
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
}
そして、これは私の非同期タスクです...
class LoadImages extends AsyncTask<String, String, String> {
ProgressDialog progDailog = new ProgressDialog(PrintBrushActivity.this);
@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog.setMessage("Loading.....");
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.show();
}
@Override
protected String doInBackground(String... aurl) {
//do something while spinning circling show
LoadImagesFromSDCard();
return null;
}
@Override
protected void onPostExecute(String unused) {
super.onPostExecute(unused);
gridView.setAdapter(new ImageAdapter(PrintBrushActivity.this));
progDailog.dismiss();
}
}
}