So I have a widget that has a list with a textview inside each item. I want to have some items have bold text and others to not.
Right now this is what I have in my ListProvider:
@Override
public RemoteViews getViewAt(int position) {
RemoteViews remoteView = new RemoteViews(
context.getPackageName(), R.layout.widget_list_item);
ListObject listObject = listObjectList.get(position);
//get whether item is a item or title
if(listObject.getClass().equals(ListItem.class)) {
//list item
ListItem listItem = (ListItem) listObject;
remoteView.setTextViewText(R.id.text, listItem.text);
}else{
//list title
ListTitle listTitle = (ListTitle) listObject;
remoteView.setTextViewText(R.id.title, listTitle.title);
}
return remoteView;
}
widget_list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/widgetTextColor"
android:gravity="center"
android:layout_marginBottom="@dimen/widget_item_padding"
android:layout_marginTop="@dimen/widget_item_padding" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/widgetTextColor"
android:gravity="center"
android:layout_marginBottom="@dimen/widget_item_padding"
android:layout_marginTop="@dimen/widget_item_padding"
android:textStyle="bold"
android:textAllCaps="true" />
</RelativeLayout>
It works but the list gets all scrambled up and messed up when scrolling because of the two textviews in the widget_list_item (text, title). Is there a simple way to change a specific item's text boldness / appearance (not size)?
Thanks!
Fixed it on my own! Super simple! I just set the unused text view to blank text.
if(listObject.getClass().equals(ListItem.class)) {
//list item
ListItem listItem = (ListItem) listObject;
remoteView.setTextViewText(R.id.title, "");
remoteView.setTextViewText(R.id.text, listItem.text);
}else{
//list title
ListTitle listTitle = (ListTitle) listObject;
remoteView.setTextViewText(R.id.text, "");
remoteView.setTextViewText(R.id.title, listTitle.title);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.