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
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
// find your TextView here by id here and update it.
Toast.makeText(context, "Clicked!!", Toast.LENGTH_SHORT).show();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With