在我調用了notifyDataSetChanged之後,我從onItemSelected得到的所有引用都是outofdate。如何以編程方式調用onItemSelected?
e.g
gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
onFront1 = (ImageView) view;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
getView
public View getView(final int position, View convertView,
ViewGroup parent) {
imView = new ImageView(this.myContext);
imView.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
imView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
ImageView view = (ImageView) v;
onFront2 = view;
return true; // indicate event was handled
}
});
onFront3 = imView;
return imView;
}
旋轉
public void rotateS(View v) {
ImageView iv = onFront;
Bitmap b = ((BitmapDrawable) iv.getDrawable()).getBitmap();
Matrix matrix = new Matrix();
matrix.postRotate(geg);
Bitmap bMapRotate = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
b.getHeight(), matrix, true);
iv.setImageBitmap(bMapRotate);
geg = 90;
Log.d("rorate", "yes");
}
onFront
引用老ImageView的,因此,我不能再使用它。我怎樣才能再次調用onItemselected?
一點更詳細:
我服用的ImageView和rotateS
函數中使用它。它使用onFront,但用全局變量onFront1 | onFront2 | onFront3替換它onFront3
onFron1允許在屏幕上出現旋轉圖像,但在notifydatasetChanged後變爲無用。
onFront2不受notifyDataSetChanged影響,但它僅在屏幕被錄製後纔有效(優先邏輯)
onFront3完全不起作用。
我想要實現 - 保持對當前imageview的引用,並在imageview更新後立即更新它。
請說清楚你的情況。你最終想達到什麼目的? – Antonio
我更新了問題,你能否修改你的答案根據新的更新? – Yarh