更新的应用程序小部件点击在android系统 [英] Update app widget on click in android
问题描述
我的工作Android小工具我widget是像下图,
[preV] 事件名称的 [下一页]
preV,其次是对widget.So的按钮,我想更新我加载的数据服务的下一步和$ P $光伏button.On开始点击事件名称并将其存储在数组列表。现在我想通过点击插件的下一步和$ P $光伏按钮在数组列表进行迭代。
所以,我怎么能实现this.Please帮我妥善解决。
这里是我的XML布局
<的LinearLayout
机器人:ID =@ + ID / lytWidget2
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =5dip
机器人:方向=横向> <按钮
机器人:ID =@ + ID / BTN previousView
机器人:layout_width =43dp
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =左|中心
机器人:背景=@绘制/ ic_leftarrow
机器人:填充=5dip/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =52dp
机器人:layout_weight =0.97
机器人:文字=事件名称/> <按钮
机器人:ID =@ + ID / btnNextView
机器人:layout_width =43dp
机器人:layout_height =FILL_PARENT
机器人:layout_gravity =右| center_vertical
机器人:背景=@绘制/ ic_rightarrow
机器人:填充=5dip/>
< / LinearLayout中>
所以,只要处理您的按钮,在这样的 AppWidgetProvider
类的click事件。
请参阅如何创建简单的小部件本很好的教程。有点击添加处理过。
样code
@覆盖
公共无效的onReceive(上下文的背景下,意图意图)
{
super.onReceive(背景下,意图); RemoteViews意见=新的RemoteViews(context.getPackageName(),R.layout.widget);
//根据ID找到你的TextView这里在这里和更新。 Toast.makeText(上下文中,已点击!!,Toast.LENGTH_SHORT).show();
}
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();
}
这篇关于更新的应用程序小部件点击在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!