【发布时间】:2017-02-03 12:16:05
【问题描述】:
我在应用程序小部件中使用 GridView。我想在小部件中的每个图像下方显示图像和文本。图像(应用程序图标)正在显示;但是没有显示文本。我正在使用 setTextViewText() 来设置文本。
WidgetViewsFactory.java 类的getViewAt()方法:
public RemoteViews getViewAt(int position) {
RemoteViews row = new RemoteViews(mContext.getPackageName(), R.layout.widget_list_row);
ApplicationInfo data = null;
Bundle extras = new Bundle();
Intent fillInIntent = new Intent(mContext, NotificationReceiverIntent.class);
PendingIntent pendingLaunchIntent;
try {
packageName = appsPackageNameList.get(position).split(";;");
data = packageManager
.getApplicationInfo(packageName[0], 0);
if (null != data) {
Bitmap icon = CommonCode.getBitmapFromIcon(data.loadIcon(packageManager));
row.setImageViewBitmap(R.id.img_widget, icon);
Log.e("count", packageName[1]);
row.setTextViewText(R.id.txt_notification_count, packageName[1]); //setting text
}
} catch (final PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return (row);
}
我正在打印给我正确值的文本(数组值)。 那么我应该怎么做才能在我的小部件中设置文本呢?
【问题讨论】: