如何创建与单个应用程序窗口小部件Android应用程序 [英] How to create android app with app widget in single application

查看:117
本文介绍了如何创建与单个应用程序窗口小部件Android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一个 Android应用程序这是存储日期与人的姓名和电话号码。

I have already done one android application which is store date with person name and phone number.

现在我要开发一个控件此应用程序,以显示今日(日期,人名,电话号码)与按钮。

Now I have to develop one widget for this application to show today (date, person name, phone number) with button.

要求:

  1. 在单一应用程序的应用程序和widget。
  2. 当我点击一个按钮,在窗口小部件,它会开始我的 应用程序。
  3. 当今天 -
  4. 在窗口小部件的数据应同步我的应用程序 天(人5和应用程序中添加5更多的人则部件显示 10人的数据)
  5. 我怎么会设计这个小工具?任何指引?我不得不使用 水平滚动视图。
  1. Single application with app and widget.
  2. When I click on a button which is in the widget, it will start my application.
  3. Widget data should always synchronize with my app - when today day (person 5 and application add 5 more person then widget display 10 person data)
  4. How could I design this widget? Any guidelines? I have to use horizontal scrollview.

我做了一个简单的小工具的演示,但我不知道如何与我的应用程序同步。

I have done a simple widget demo but I don't know how to synchronize it with my application.

请分享你的经验,让我的小工具和应用程序的一些想法。

Please share your experience and give some idea about my widget and application.

推荐答案

我发现夫妇一天我得到了一些我是怎么solution.so分享我的想法。

I am finding couple of day i got some how solution.so i am share my idea.

本网站对我来说是非常有用的。

This site is very useful for me.

http://kasperholtze.com/android/how -to-MAKE-A-简单的Andr​​oid窗口小部件/

我做出一些改变,做我的工作。

I make some changes and done my work.

要求的解决方案:

1 请接收并投入清单允许这样。

1. Make Receiver and put into manifest permission like this.

<receiver
        android:name=".WatchWidget"
        android:label="WatchWidget" >
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        </intent-filter>
        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/watch_widget_provider" />
    </receiver>

2 在我的身边需要顶级的TextView点击这样可以使通过texview ID在的OnUpdate()

2. In My side require top textview click so can make using texview id in onUpdate().

    remoteViews = new RemoteViews(context.getPackageName(),R.layout.widget_lay);

    Intent intent = new Intent(context, TestActivity.class);
    intent.setAction("callActivity");
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
    remoteViews.setOnClickPendingIntent(R.id.widget_textview, pendingIntent); 
    appWidgetManager.updateAppWidget(new ComponentName(context,WatchWidget.class), remoteViews);

3。我要调用数据库并获取记录并显示it.now问题,怎么样更新?

3. I want to call database and fetch record and display it.now question what about update?

所以我使用Timer类和运行,因为过小部件随时更新每隔30分钟1000sec(可能)。

so i am used timer class and run every 1000sec because of over widget is always update 30min(may be).

@Override
public void onUpdate( final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds )
{

    this.appWidgetManager = appWidgetManager;
    try {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager,appWidgetIds), 1, 1000);

    } catch (Exception e) {
        System.out.println("Exception:");
    }
    updateSwitch1(context, appWidgetManager, appWidgetIds[0]);

}

如果有任何查询,然后把意见,并感谢所有给予我充分的支持,使这个答案很有用的。

If any have query then put comment and thanks to all which give me full support to make this answer useful.

这篇关于如何创建与单个应用程序窗口小部件Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆