VK.*_*Dev 4 android android-widget android-appwidget
我正在使用Android Widget我的小部件就像下图, [上一页] 事件名称 [下一页]
上一页,接下来是widget上的按钮.所以我想点击next和prev按钮更新事件名称.在服务开始时,我加载了数据并将其存储在数组列表中.现在我想通过单击小部件上的next和prev按钮来遍历数组列表.
那么我怎样才能实现这一目标.请帮助我找到合适的解决方案.这是我的xml布局
<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>
Run Code Online (Sandbox Code Playgroud)
Tom*_*ski 10
所以,只需AppWidgetProvider像这样处理类中按钮的点击事件.请参阅这个关于如何创建简单小部件的好教程.还添加了点击处理程序.
示例代码
@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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7827 次 |
| 最近记录: |