I am working on Android Widget my widget is like following diagram, [prev] event name [next]
prev, next are the buttons on the widget.So i want to update the event name on click of next and prev button.On start of the service i loaded the data and stored it in array list. Now i want to iterate through the array list by clicking the next and prev buttons on the widget.
So how can i achieve this.Please help me with proper solution. Here is my xml layout
<LinearLayout
android:id="@+id/lytWidget2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal" >
<Button
android:id="@+id/btnPreviousView"
android:layout_width="43dp"
android:layout_height="fill_parent"
android:layout_gravity="left|center"
android:background="@drawable/ic_leftarrow"
android:padding="5dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="52dp"
android:layout_weight="0.97"
android:text="Event Name" />
<Button
android:id="@+id/btnNextView"
android:layout_width="43dp"
android:layout_height="fill_parent"
android:layout_gravity="right|center_vertical"
android:background="@drawable/ic_rightarrow"
android:padding="5dip" />
</LinearLayout>
So, just handle the click events of your buttons in the
AppWidgetProvider
class like this. See this good tutorial on how to create simple widget. There are click handlers added too.Sample code
First, in your
WidgetProviderClass
you should define your actions so that you could differentiate them. In this case:Next, in your overrided
onUpdate()
funcion you should put:Function for creating an intent that's directed to the current class (to itself):
When the event occurs
onReceive()
function will be called:BONUS: If you want to call the
onUpdate()
function here is a function that will do that for you. It requires only the context parameter!