这是我的片段的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.thenewjonathan.foodtracker.fragments.FoodItemDisplay"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="50dp"
android:textStyle="bold"
android:text="blank"
android:id="@+id/foodItemNameView"
android:gravity="center"
android:layout_gravity="top|left|center"
android:textAlignment="center"/>
<ImageView
android:contentDescription="@string/foodPicture"
android:layout_width="241dp"
android:layout_height="241dp"
android:layout_gravity="left|center_vertical"
android:background="@color/material_blue_grey_800"
android:layout_below="@id/foodItemNameView"
android:id="@+id/foodPic"
/>
<RelativeLayout
android:layout_width="140dp"
android:layout_height="241dp"
android:layout_alignParentRight="true"
android:layout_below="@id/foodItemNameView"
android:layout_gravity="end|center_vertical"
android:gravity="center"
android:id="@+id/checkBoxGroup"
>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monday"
android:id="@+id/mondayBox"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tuesday"
android:id="@+id/tuesdayBox"
android:layout_below="@id/mondayBox"
android:layout_alignParentStart="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wednesday"
android:id="@+id/wednesdayBox"
android:layout_below="@id/tuesdayBox"
android:layout_alignParentStart="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thursday"
android:id="@+id/thursdayBox"
android:layout_below="@id/wednesdayBox"
android:layout_alignParentStart="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friday"
android:id="@+id/fridayBox"
android:layout_below="@id/thursdayBox"
android:layout_alignParentStart="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Saturday"
android:id="@+id/saturdayBox"
android:layout_below="@id/fridayBox"
android:layout_alignParentStart="true"/>
<CheckBox
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) java android intellij-idea android-fragments fragmentmanager
我有一个名为TransactionWrapper的类,我用它在我的应用程序中为TableView填充我的ObservableList.此包装器具有一个属性(枚举),指示它是提款还是存款.我需要达到这个目的来渲染/格式化金额单元格(根据交易的性质以红色或绿色显示)并且我找不到任何可以帮助我完成这场战斗的东西.
基本上我想要做的就是查看行并说出类型是否为提取,将文本颜色设置为红色,如果是存储颜色则为绿色......我希望有人可以帮我解决这个问题.正如我在其他地方发现的那样,我将使用setCellFactory在我的尝试下面发布.这种方法允许我格式化单元格及其显示方式,但问题出在updateItem函数内部,我可以得到我的事务类型的值.
amountCol.setCellFactory(new Callback<TableColumn<TransactionWrapper, String>, TableCell<TransactionWrapper, String>>()
{
@Override
public TableCell<TransactionWrapper, String> call(
TableColumn<TransactionWrapper, String> param)
{
return new TableCell<TransactionWrapper, String>()
{
@Override
protected void updateItem(String item, boolean empty)
{
if (!empty)
{
// should be something like (transaction.getType().equals(TransactionTypes.DEPOSIT) ? true : false;)
boolean isDeposit = true;
setText(item);
if(isDeposit) // should be if type is deposit
{
setTextFill(Color.GREEN);
}
else
{
setTextFill(Color.RED);
}
}
}
};
}
});
Run Code Online (Sandbox Code Playgroud)
以下是我如何设置我的专栏:
amountCol.setCellValueFactory(cellData -> cellData.getValue().getAmountString());
Run Code Online (Sandbox Code Playgroud)
这是一个名为TransactionWrapper的对象,其中包含:
private final StringProperty transactionTypeString;
private final StringProperty …Run Code Online (Sandbox Code Playgroud)