Possible Duplicate:
Button next and prev not working
I have 5 buttons in my layout and on the next button i want to change the text of the button which is from a arraylist. how could i implement this?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout style="@style/verticallayout" >
<Button
android:id="@+id/b1"
style="@style/buttons"
android:layout_weight=".16"
android:text="1" />
</LinearLayout>
<LinearLayout style="@style/verticallayout" >
<Button
android:id="@+id/b2"
style="@style/buttons"
android:layout_weight=".16"
android:text="2 />
</LinearLayout>
<LinearLayout style="@style/verticallayout" >
<Button
android:id="@+id/b3"
style="@style/buttons"
android:layout_weight=".16"
android:text="3" />
</LinearLayout>
<LinearLayout style="@style/verticallayout" >
<Button
android:id="@+id/b4"
style="@style/buttons"
android:layout_weight=".16"
android:text="4" />
</LinearLayout>
<LinearLayout style="@style/verticallayout" >
<Button
android:id="@+id/b5"
style="@style/buttons"
android:layout_weight=".16"
android:text="5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/left"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:enabled="false"
android:text="Prev" />
<Button
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:text="Next" />
</LinearLayout>
my java class::
here count is the static variable.
public void onClick(View arg0) {
String a=null;
switch(arg0.getId()){
case R.id.left:
if( count==0)
prev.setEnabled(false);
else{
count--;
}
break;
case R.id.right:
if( count>5)
next.setEnabled(false);
else{
count++;
}
break;
case R.id.b1:
a=(( count*0)+0)+"";
bb1.setText(a);
}
break;
case R.id.b2:
a= (( count*0)+1)+"";
bb2.setText(a);
}
break;
case R.id.b3:
a= (( count*0)+2)+"";
bb3.setText(a);
}
break;
case R.id.b4:
a= ((count*0)+3)+"";
bb4.setText(a);
}
break;
case R.id.b5:
a= ((count*0)+4)+"";
bb5.setText(a);
}
break;
}
}
i want the button text to be changed by the value of count. but the values are not changing.
my doubt is that is there a need to refresh the acctivity after every click of next and prev
The problem is, you are trying to change the Text of the Buttons in the Click Event of their self.
So, when you click next or prev, the text in the buttons won’t change(only count changes). They only change(actually updated with latest count values) when you click on them(b1,2,3,4,5).
So, to get what you required do this:
}
by which you are changing the text of the buttons on click of the next and prev buttons