一切拉圖像正常工作只是圖片不顯示如何通過gridview的位置
BaseAdapter:
public Bitmap getItem(int position) {
return bitmaps.get(position);
}
活動:
Intent i = new Intent(getApplicationContext(), SpcifiesImage.class);
// passing array index
i.putExtra("id", position);`enter code here`
startActivity(i);
這是我想要的活動那圖像會有:
Intent intent = new Intent(getApplicationContext(), SpcifiesImage.class);
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
CustomGrid imageAdapter = new CustomGrid(mContext);
ImageView imageView = (ImageView) findViewById(R.id.imageView3);
imageView.setImageBitmap(imageAdapter.bitmaps.get(position));
// passing array index
intent.putExtra("mas", massage);
startActivity(intent);
CustomGrid:
Context mContext;
private Bitmap btimaprecieve;
List<ParseObject> ParseObjects;
ArrayList<Bitmap> bitmaps;
ParseQuery<ParseObject> query;
ProgressDialog progressDialog;
int size;
public CustomGrid(Context c, ArrayList<Bitmap> bitmaps) {
mContext = c;
this.bitmaps = bitmaps;
}
public CustomGrid(Context mContext) {
}
//---returns the number of images---
public int getCount() {
return bitmaps.size();
}
//---returns the ID of an item---
public Bitmap getItem(int position) {
return bitmaps.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(mContext);
// get layout from mobile.xml
gridView = inflater.inflate(R.layout.mobile, null);
// set value into textview
// TextView textView = (TextView) gridView.findViewById(R.id.grid_item_label);
// textView.setText(mobileValues[position]);
// set image based on selected text
ImageView imageView = (ImageView) gridView
.findViewById(R.id.grid_item_image);
// imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
// imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageBitmap(bitmaps.get(position));
} else {
gridView = (View) convertView;
}
return gridView;
logcat的:
過程:com.example.tepper.myapplication,PID:16637 顯示java.lang.NullPointerException:嘗試調用虛擬方法「布爾android.graphics.Bitmap。壓縮(android.graphics.Bitmap $ CompressFormat,INT,java.io.OutputStream中的)」對空對象引用
可以顯示代碼填充適配器映像嗎? – MightySeal
哪個代碼...? – avichai80
我在猜測@MightySeal是指'CustomGrid'代碼。 您所指的位置是用戶選擇的GridView上圖像的位置?或者你以另一種方式獲得這個職位?我想我沒有完全理解你的問題。 –