【发布时间】:2018-07-10 15:36:31
【问题描述】:
Listview 是可滚动的,因此它不会通过动态调整其行大小来匹配父级。是否可以从数组中获取数据并将它们单独传递给活动,以便我可以改用LinearLayout?
RemoteViews mainView = new RemoteViews(context.getPackageName(), R.layout.main_widget_layout);
for (int i = 0; i < 16; i++) {
RemoteViews textView = new RemoteViews(context.getPackageName(), R.layout.text_append_layout);
textView.setTextViewText(R.id.appending_text, String.valueOf(i));
mainView.addView(R.id.text_data_viewer, textView);
Intent fillInIntent = new Intent();
fillInIntent.putExtra("extradata", i);
textView.setOnClickFillInIntent(R.id.appending_text, fillInIntent);
}
Intent activitytoStart = new Intent(context, Widget.class).setAction("com.custom.action");
mainView.setPendingIntentTemplate(R.id.text_data_viewer, PendingIntent.getBroadcast(context, 0, activitytoStart, PendingIntent.FLAG_UPDATE_CURRENT));
main_widget_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_data_viewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="16"
android:orientation="vertical"/>
text_append_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appending_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" />
【问题讨论】:
-
根本没有人帮忙。几个月前,其他成员真的很有帮助。
标签: java android android-widget android-pendingintent android-appwidget