【问题标题】:How to open an external link from homescreen widget's listview?如何从主屏幕小部件列表视图打开外部链接?
【发布时间】:2017-03-01 16:28:30
【问题描述】:

我有一个主屏幕小部件,其中填充了列表视图中的数据。每行都与一个链接相关联,点击一个项目,我想打开相关联的 url。

除了每个项目的 onclicklistener 之外,我已经设置了所有内容。我遇到过类似的问题,但它们都是关于打开活动的,而我想打开一个外部链接。

这是我在扩展 AppWidgetProvider 的类中的 onUpdate():

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

    for (int i = 0; i < appWidgetIDs.length; i++) {
        final RemoteViews remoteViews;
        final int id = appWidgetIDs[i];
        remoteViews = new RemoteViews(
                        context.getPackageName(),R.layout.widget_layout);
       remoteViews.setRemoteAdapter(R.id.widget_list,
                        getIntent(context, id));
       updateWidget(appWidgetManager, id, remoteViews);

    super.onUpdate(context, appWidgetManager, appWidgetIDs);
}

这是我从 RemoteViewsFactory 获取的 getViewAt():

@Override
public RemoteViews getViewAt(int position) {
    row = new RemoteViews(context.getPackageName(), R.layout.widget_row);
    final ModelClass modelClass = AppWidget.filteredList.get(position);
    row.setTextViewText(R.id.title, modelClass.getTitle());
    return row;
}

【问题讨论】:

    标签: java android listview android-widget


    【解决方案1】:

    使用网络视图,在每个项目上单击实例化网络视图。我会和这个图书馆一起去,它真的很漂亮。 https://github.com/TheFinestArtist/FinestWebView-Android

    【讨论】:

    • 如何将 URL 与意图打包,以及如何检索我的 AppWidgetProvider 的 URL?
    • 您知道,如果不看您所描述的结构,先生,我无法回答这个问题。
    • 更新了问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 2018-08-05
    相关资源
    最近更新 更多