Flip button positions in linear layout vertical - android

well i'm looking for a way to flip the button on a linear layout vertical here is a screen shot of the buttons
the xml code is
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:id="#+id/buttons_layout">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iv_green"
android:layout_weight="1.0"
android:src="#drawable/leaf_green"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"
android:onClick="HandleClick" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iv_other"
android:layout_weight="1.0"
android:src="#drawable/leaf_other"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"
android:onClick="HandleClick" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iv_red"
android:layout_weight="1.0"
android:src="#drawable/leaf_red"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"
android:onClick="HandleClick" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/iv_yellow"
android:layout_weight="1.0"
android:src="#drawable/leaf_yellow"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"
android:onClick="HandleClick" />
</LinearLayout>
what i want to do is that when i push flip button on (which is another button) i want to change the position of the current button i will explain in pics:
okay guys i used the idea that Arnab Told me about in the post below, well i want to randomly flip the image buttons so i did the following script:
public void onClick(View v) {
btnsLayout.removeAllViews();
ArrayList<Integer> a = new ArrayList<Integer>();
for(int i = 0; i < 4; i++)
{
a.add(i);
}
Collections.shuffle(a);
btnsLayout.addView(Other, a.get(0).intValue());
btnsLayout.addView(Green, a.get(1).intValue());
btnsLayout.addView(Red,a.get(2).intValue());
btnsLayout.addView(Yellow,a.get(3).intValue());
}
the application is crashing the crash reason is:
java.lang.IndexOutOfBoundsException: index=2 count=1
what does it means ?
Thank you !

You can do this inside onCLick(View view) of Flip Button:
// Get all the views
LinearLayout btnsLayout = (LinearLayout) findViewById(R.id.buttons_layout);
ImageButton ivGreen = (ImageButton) findViewById(R.id.iv_green);
ImageButton ivOther = (ImageButton) findViewById(R.id.iv_other);
ImageButton ivRed = (ImageButton) findViewById(R.id.iv_red);
ImageButton ivYellow = (ImageButton) findViewById(R.id.iv_yellow);
// Remove views
btnLayout.removeView(ivGreen);
btnLayout.removeView(ivRed);
// ReAdd views in new index[Index 0 = position 1, Index 2 = position 3]
btnLayout.addView(ivRed, 0);
btnLayout.addView(ivGreen, 2);
Similarly :
// Remove views
btnLayout.removeView(ivOther);
btnLayout.removeView(ivYellow);
// ReAdd views in new index[Index 1 = position 2, Index 3 = position 4]
btnLayout.addView(ivYellow, 1);
btnLayout.addView(ivOther, 3);

First, you should rename the ids of the ImageButtons like :
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/first_leaf"
android:layout_weight="1.0"
android:src="#drawable/leaf_green"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"
android:onClick="HandleClick" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/second_leaf"
android:layout_weight="1.0"
android:src="#drawable/leaf_other"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"
android:onClick="HandleClick" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/third_leaf"
android:layout_weight="1.0"
.../>
Then find your flip button in your java class and set an OnClickListener
like this:
myFlipButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
}):
Then, in the onClick function, perform the changes:
myFlipButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
myFirstLeaf.setImageDrawable(getResources().getDrawable(R.drawable.leaf_red));
mySecondLeaf.setImageDrawable(getResources().getDrawable(R.drawable.leaf_yellow));
...
}
});
Hope it helps.

You can use the imgButton.setBackgroundResource(); method.
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
imgButton1.setBackgroundResource(R.drawable.image3);
imgButton3.setBackgroundResource(R.drawable.image1);
}
});
If you want to swap the views you need to use a ViewGroup and you can set the index accordingly.
How do I change the position of a view in a Linear Layout.?

Hello Using Arnab Suggestion and some tuning i found a solution: the problem was that you need to insert the index 1 2 3 4 you can't randomly add the views to the linear layout.
public void addListenerOnButton() {
Button flip = (Button) findViewById(R.id.btn_flip);
final LinearLayout btnsLayout = (LinearLayout) findViewById(R.id.buttons_layout);
final ImageView Other = (ImageView) findViewById(R.id.iv_other);
final ImageView Green = (ImageView) findViewById(R.id.iv_green);
final ImageView Red = (ImageView) findViewById(R.id.iv_red);
final ImageView Yellow = (ImageView) findViewById(R.id.iv_yellow);
flip.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
btnsLayout.removeAllViews();
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 0; i < 4; i++) {
a.add(i);
}
Collections.shuffle(a);
for (int k = 0; k<=3 ; k++){
if (a.get(0).intValue() == k) {
btnsLayout.addView(Other, a.get(0).intValue());
}
if (a.get(1).intValue() == k) {
btnsLayout.addView(Green, a.get(1).intValue());
}
if (a.get(2).intValue() == k) {
btnsLayout.addView(Red, a.get(2).intValue());
}
if (a.get(3).intValue() == k) {
btnsLayout.addView(Yellow, a.get(3).intValue());
}
}
}

Related

Add custom layout to ConstraintLayout programmatically

Good day everyone.
I'm trying to a layout to a ConstraintLayout in a for-loop.
The layout is decalred as follows:
public class SingleMeal extends ConstraintLayout {
private TextView food_id;
private ImageButton spacer_minus;
private ImageButton spacer_plus;
private TextView food_quantity;
public SingleMeal(Context context) {
super(context);
init();
}
private void init(){
inflate(getContext(), R.layout.activity_single_meal, this);
this.food_id = findViewById(R.id.food_id);
this.spacer_minus = findViewById(R.id.spacer_minus);
this.spacer_plus = findViewById(R.id.spacer_plus);
this.food_quantity = findViewById(R.id.food_quantity);
}
public void setFood_id(String food_id) {
this.food_id.setText(food_id);
}
public TextView getFood_quantity() {
return food_quantity;
}
public ImageButton getSpacer_minus() {
return spacer_minus;
}
public ImageButton getSpacer_plus() {
return spacer_plus;
}
}
The xml of the layout is as follows:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".selectMeals.SingleMeal">
<TextView
android:id="#+id/food_id"
android:layout_width="wrap_content"
android:layout_height="#dimen/edit_text_height"
android:layout_marginStart="#dimen/medium_space"
android:gravity="center"
android:textSize="#dimen/text_size"
android:layout_alignParentStart="true"/>
<LinearLayout
android:id="#+id/layout_food_quantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/medium_space"
android:orientation="horizontal"
android:layout_alignParentEnd="true">
<ImageButton
android:id="#+id/spacer_minus"
android:layout_width="#dimen/plus_minus"
android:layout_height="#dimen/plus_minus"
android:background="#drawable/minus"
android:contentDescription="#string/spacer"/>
<TextView
android:id="#+id/food_quantity"
android:layout_width="#dimen/info_quantity"
android:layout_height="#dimen/edit_text_height"
android:gravity="center"
android:text="0"
android:singleLine="true"
android:textSize="#dimen/text_size" />
<ImageButton
android:id="#+id/spacer_plus"
android:layout_width="#dimen/plus_minus"
android:layout_height="#dimen/plus_minus"
android:background="#drawable/plus"
android:contentDescription="#string/spacer"/>
</LinearLayout>
</RelativeLayout>
On the main activity I'm creating a new SingleMeal object, and populate it it's methods.
ConstraintLayout previousCourse = null;
for (Course course : meal.getCourses()) {
final SingleMeal food_container = new SingleMeal(this);
food_container.setId(View.generateViewId());
food_container.setFood_id(course.getName());
final TextView food_quantity = food_container.getFood_quantity();
ImageButton minus = food_container.getSpacer_minus();
minus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String foodQuantity = food_quantity.getText().toString();
int foodQuantityInt = Integer.parseInt(foodQuantity) > 0 ? Integer.parseInt(foodQuantity) - 1 : Integer.parseInt(foodQuantity);
food_quantity.setText(String.valueOf(foodQuantityInt));
}
});
ImageButton plus = food_container.getSpacer_plus();
plus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String foodQuantity = food_quantity.getText().toString();
int foodQuantityInt = Integer.parseInt(foodQuantity) + 1;
food_quantity.setText(String.valueOf(foodQuantityInt));
}
});
lunchCountainer.addView(food_container);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(lunchCountainer);
if (previousCourse == null)
constraintSet.connect(food_container.getId(), ConstraintSet.TOP , findViewById(R.id.txt_menu_date).getId(), ConstraintSet.BOTTOM,0);
else
constraintSet.connect(food_container.getId(), ConstraintSet.TOP , previousCourse.getId(), ConstraintSet.BOTTOM,0);
constraintSet.applyTo(lunchCountainer);
previousCourse = food_container;
}
I'm probably doing something very wrong as it goes trough the loop without any error, but it is not showing anything in the end.
The lunchContainer as previously said is a ConstraintLayout (inside a ScrollView):
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/lunch_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:isScrollContainer="true"
android:orientation="vertical"
android:scrollbarStyle="outsideOverlay"
android:scrollbars="vertical" />
Any idea?
It seems like you don't want a ConstraintLayout here, if you are stacking the items vertically I would suggest a LinearLayout set to Vertical.
Set the width of each item to MATCH_PARENT, then set the layout weight to be the same on each item, but make sure the height is set to WRAP_CONTENT so the sizes are the same for each item.
Not 100% sure this will work but this is the way to do it.
Or you could use a ListView, with your items within that, this will also handle scrolling etc for you.
Either option will work for you.

Android : Apply animation in onClick to all views in a loop

I have a simple linearlayout with say, 10 Textviews inside it.I want to apply to apply the zoomin animation to textview in onClick.I set the OnclickListener to all the textviews inside a loop and also apply the animation.
PROBLEM : when i click on any textview all the previously clicked textviews also zooms in.
layout.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linear">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"/>
...
...
...
</LinearLayout>
MainActivity.java
List<TextView> txs = new ArrayList<>();
for(int i = 0;i < linear.getChildCount();i++){
txs.add(linear.getChildAt(i));
}
// OnCLick Listener
public void setListener(){
for (int i = 0;i < linear.size();i++){
linear.get(i).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
v.startAnimation(anim_zoomin);
}
});
}
}
whats the issue??
Let's say I begin with a view that is completely zoomed out, which means it's scale parameters have been set to zero (programatically in this case).
view.setScaleX(0f);
view.setScaleY(0f);
To zoom-in, all I would have to do is check the scale parameters of the view and animate the view only if the parameter == 0.
if (view.getScaleX() == 0) {
view.animate().scaleX(1f).setDuration(100L);
view.animate().scaleY(1f).setDuration(100L);
}

When using ViewPropertyAnimation, property of the object does not change

I have a test code using the View Property Animation to switch locations of two buttons. The code is as below:
public class TestAnimationActivity extends Activity {
private View mainView;
private View TempView;
private Button B1, B2, B3;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate your view
setContentView(R.layout.main_test);
mainView = findViewById(R.id.mainTest);
B1 = (Button) mainView.findViewById(R.id.B1);
B2 = (Button) mainView.findViewById(R.id.B2);
B3 = (Button) mainView.findViewById(R.id.B3);
OnClickListener OCL = new OnClickListener(){
#Override
public void onClick(View v) {
if(TempView == null){
TempView = v;
}else{
int originalPos1[] = new int[2];
TempView.getLocationOnScreen( originalPos1 );
int originalPos2[] = new int[2];
v.getLocationOnScreen( originalPos2 );
v.animate().translationX((float)originalPos1[0] - (float)originalPos2[0]);
v.animate().translationY((float)originalPos1[1] - (float)originalPos2[1]);
TempView.animate().translationX((float)originalPos2[0] - (float)originalPos1[0]);
TempView.animate().translationY((float)originalPos2[1] - (float)originalPos1[1]);
TempView = null;
}
}};
B1.setOnClickListener(OCL);
B2.setOnClickListener(OCL);
B3.setOnClickListener(OCL);
}
}
The XML file is as below
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainTest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/B1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#B4B4B4"
android:gravity="center" />
<Button
android:id="#+id/B2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#470047"
android:gravity="center" />
<Button
android:id="#+id/B3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center" />
</LinearLayout>
When I was testing this code on my phone. The animation did not work properly.
Two buttons will switch position the first time, but the button will go to wrong position if I continue clicking them. It seems that the button still calculate the position it should move to based on its original location when the app launched.
Anyone knows what is going wrong?

Android: many equal Buttons, onclick doesn't work for certain

I have seven equal Buttons in LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:weightSum="7" >
<Button
android:id="#+id/btn_mon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1"
android:background="#color/white"
android:text="0" />
<Button
android:id="#+id/btn_tus"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="0"
android:background="#color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btn_wen"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="0"
android:background="#color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btn_thu"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="0"
android:background="#color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btn_fri"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="0"
android:background="#color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btn_sat"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="0"
android:background="#color/white"
android:layout_weight="1"/>
<Button
android:id="#+id/btn_sun"
android:layout_width="50dp"
android:layout_height="50dp"
android:text="0"
android:background="#color/white"
android:layout_weight="1"/>
</LinearLayout>
Their OnClickListener is also equal (and initializing too):
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.calendar_row, null);
}
final Button btn_mon = (Button)convertView.findViewById(R.id.btn_mon);
final Button btn_tus = (Button)convertView.findViewById(R.id.btn_tus);
final Button btn_wen = (Button)convertView.findViewById(R.id.btn_wen);
final Button btn_thu = (Button)convertView.findViewById(R.id.btn_thu);
final Button btn_fri = (Button)convertView.findViewById(R.id.btn_fri);
final Button btn_sat = (Button)convertView.findViewById(R.id.btn_sat);
final Button btn_sun = (Button)convertView.findViewById(R.id.btn_sun);
btn_mon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_mon, weekdays.get(0).data); }});
btn_tus.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_tus, weekdays.get(1).data); }});
btn_wen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_wen, weekdays.get(2).data); }});
btn_thu.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_thu, weekdays.get(3).data); }});
btn_fri.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_fri, weekdays.get(4).data); }});
btn_sat.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_sat, weekdays.get(5).data); }});
btn_sun.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_sun, weekdays.get(6).data); }});
onCalBtnClick method:
private void onCalBtnClick(Button btn, int day){
Log.d("debug", String.valueOf(day));
btn.setTextColor(mContext.getResources().getColor(R.color.orange));
//selectedYear, month are global
Intent intent = new Intent();
intent.putExtra("year", selectedYear);
intent.putExtra("month", month);
intent.putExtra("day", day);
setResult(RESULT_OK, intent);
finish();
}
However, if I put Log.d into onCalBtnClick method (it is called from each clicklistener), only middle three buttons work. Two buttons from left side (btn_mon, btn_tus) and two buttons from right side (btn_sat, btn_sun) don't react on user click. Middle buttons work fine.
This is similar question Android LinearLayout make button doesn't work but my layout file corresponds to pattern in the answer there and buttons don't work nevertheless
UPDATE
When I removed fixed button height and width in layout file (from 50dp to wrap_content), all buttons started to work!
However, now it doesn't look as needed. There's space needed between text's on buttons.
And main question: WHY?
If you using weights in your layout, you are telling that it should be filled with some objects with some proportions. It just opposite to "wrap_content". With weights outer layout defines size of inner views, while "wrap_content" means that outer layout size is defined by inner views.
Please decide what approach is better in that case - removing weights or fixed inner views sizes.
set your Linear Layout's Width and Height to FILL_PARENT .it will work for sure.
Try to declare all your setOnClickListener for buttons outside of your adapter class and after initialization of weekdays array.
That will solve your problem.
Or try to set condition like this for all buttons :
if (btn_mon != null && position < weekdays.size()) {
btn_mon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { onCalBtnClick(btn_mon, weekdays.get(0).data); }});
}

Using ViewFlipper with onclick to switch views

I'm using ViewFLipper with Random.nextInt(). to change layouts onClick (Button). Now I have 3 xml layouts. 1_view.xml 2_view.xml 3_view.xml. Starting from 1_view.xml I have a button there. When button clicked I should get a random layout. it works. But the problem is now, sometimes I get the same layout (1_view.xml). When a user clicks a button on (1_view.xml), I want them to go to the layouts I have left (2_view.xml and 3_view.xml).
Codes
Main.xml
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:id="#+id/TVLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="left|top"
android:text="0"
android:textColor="#4CB848"
android:textSize="40sp"
android:textStyle="bold" />
<TextView
android:id="#+id/TVRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/TVLeft"
android:gravity="right"
android:text="0"
android:textColor="#FF0000"
android:textSize="40sp"
android:textStyle="bold" />
</RelativeLayout>
<ViewFlipper
android:id="#+id/viewFlipper1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<include
android:id="#+id/1_View"
layout="#layout/1_view" />
<include
android:id="#+id/2_View"
layout="#layout/2_view" />
<include
android:id="#+id/3_View"
layout="#layout/3_view" />
</ViewFlipper>
</LinearLayout>
Main.java
// FlipperView
MyViewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
TVRight = (TextView) findViewById(R.id.TVRight);
TVLeft = (TextView) findViewById(R.id.TVLeft);
// 1_view.xml
Q1_btn1 = (Button) findViewById(R.id.btn_1);
Q1_btn2 = (Button) findViewById(R.id.btn_2);
Q1_btn3 = (Button) findViewById(R.id.btn_3);
Q1_btn4 = (Button) findViewById(R.id.btn_4);
Q1_btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Wrongnum++;
WrongResult.setText(Integer.toString(Wrongnum));
}
});
Q1_btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Rightnum++;
RightResult.setText(Integer.toString(Rightnum));
Random RandomView = new Random();
MyViewFlipper.setDisplayedChild(RandomView.nextInt(3));
}
});
Q1_btn3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Wrongnum++;
WrongResult.setText(Integer.toString(Wrongnum));
}
});
Q1_btn4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Wrongnum++;
WrongResult.setText(Integer.toString(Wrongnum));
}
});
You can do this in your code:
Random RandomView = new Random();
int nextViewIndex = RandomView.nextInt(3);
while (nextViewIndex == MyViewFlipper.getDisplayedChild()) {
nextViewIndex = RandomView.nextInt(3);
}
MyViewFlipper.setDisplayedChild(nextViewIndex);
Basically just call Random.nextInt() until it doesn't match current viewFlipper's index.
To only show a viewFlipper once randomly:
// Intialize this once
List<Integer> vfIndices = new ArrayList<Integer>();
for (int i = 0; i < MyViewFlipper.getChildCount(); i++) {
vfIndices.add(i);
}
// when button is clicked
if (vfIndices.size() == 0) {
return; // no more view flipper to show!
}
int viewIndex = RandomView.nextInt(vfIndices.size());
MyViewFlipper.setDisplayedChild(vfIndices.get(viewIndex));
vfIndicies.remove(viewIndex);
The idea is use an ArrayList to keep track of the viewFlipper index that has not been shown. When button is clicked, pick an index randomly from this array and set the viewFlipper to. Then remove that index from the ArrayList. Next time the button is clicked, it will show one of the remaining flippers.

Categories

Resources