Set ViewFlipper in order
I'm writing an Android app that is basically a ListView populated with an array of strings. The array position is passed to a "details" activity, which sets one of 6 different XML layouts, based on the position id that is passed. The XML layouts are ViewFlippers and开发者_高级运维 I'd like the user to be able to fling back and forth between them. I mostly have it working, except the item the user selected in the ListView is always the first item on the "details" page. So if a user selected the 3rd item in the ListView, the 3rd item is shown, but if they swipe to the right, then the 1st "details" layout is shown, not the 4th, so everything is out of order. This is the code I'm using to populate the ViewFlipper:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bun = getIntent().getExtras();
int position = bun.getInt("position");
setContentView(fullId[position]);
viewFlipper = (ViewFlipper)findViewById(flipId[position]);
for (int i = 0; i < fullId.length; i++)
viewFlipper.addView(ViewFlipper.inflate(this, fullId[i], null));
slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_left_in);
slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_left_out);
slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_right_in);
slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_right_out);
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
}
private Integer[] fullId = {
R.layout.details1,
R.layout.details2,
R.layout.details3,
R.layout.details4,
R.layout.details5,
R.layout.details6,
R.layout.details7,
};
private Integer[] flipId = {
R.id.flip1,
R.id.flip2,
R.id.flip3,
R.id.flip4,
R.id.flip5,
R.id.flip6,
R.id.flip7,
};
I was hoping I could populate the ViewFlipper first with the addView's, then use getChildAt[position], but that doens't seem to work.
i dont understand y u r using so many layouts of View Flippers..
If they have the same same layout , u shud use a single View Flipper, & Flip Views within.
If u wanna change the contents of the view Flipper, u need to change the content of the View within it.. like image.setImageResource(imageId[2])
or textview.setText("###")
精彩评论