2015-07-05 48 views
0

一切拉圖像正常工作只是圖片不顯示如何通過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中的)」對空對象引用

+0

可以顯示代碼填充適配器映像嗎? – MightySeal

+0

哪個代碼...? – avichai80

+0

我在猜測@MightySeal是指'CustomGrid'代碼。 您所指的位置是用戶選擇的GridView上圖像的位置?或者你以另一種方式獲得這個職位?我想我沒有完全理解你的問題。 –

回答

0

好了,從你們發佈的代碼,你有這部分的問題:

在CustomG排除:

public CustomGrid(Context mContext) { 
} 

構造函數是空的,這意味着,當你這樣做:

CustomGrid imageAdapter = new CustomGrid(mContext); 

ImageView imageView = (ImageView) findViewById(R.id.imageView3); 
imageView.setImageBitmap(imageAdapter.bitmaps.get(position)); 

bitmaps數組將不會被初始化。 你必須要麼使位圖陣列靜態或將其存儲在可從另一個活動進行訪問的地方,只是爲了測試的目的,這樣做:

  • 變化CustomGrid以下行:

    ArrayList<Bitmap> bitmaps;public static ArrayList<Bitmap> bitmaps;

  • 然後在接下來的活動獲得這樣的:

    imageView.setImageBitmap(CustomGrid.bitmaps.get(position));

+0

是的,我做過之前,它的工作還沒有.. – avichai80

+0

,這個代碼是不是代碼,因爲它再次運行部門沒有意義 – avichai80

+0

對不起,我仍然不知道你在問什麼?試着發佈你的'CustomGrid'類代碼和你的XML佈局代碼,也許這將澄清你的問題 –