data class RideDate(var enddate: String? = null,var startdate: String? = null)
fun main(args: Array<String>) {
var listOfRideDate = mutableListOf<RideDate>();
val date1 = RideDate()
date1.startdate = "2018-11-05 00:00:00 +0000"
date1.enddate = "2018-11-06 23:59:59 +0000"
listOfRideDate.add(date1)
val date2 = RideDate()
date2.startdate = "2020-01-20 00:00:00 +0000"
date2.enddate = "2020-02-20 00:00:00 +0000"
listOfRideDate.add(date2)
val date3 = RideDate()
date3.startdate = "2020-03-20 00:00:00 +0000"
date3.enddate = "2020-03-20 00:00:00 +0000"
listOfRideDate.add(date3)
val date4 = RideDate()
date4.startdate = "2020-04-20 00:00:00 +0000"
date4.enddate = "2020-04-20 00:00:00 +0000"
listOfRideDate.add(date4)
val …Run Code Online (Sandbox Code Playgroud) 我使用复数来简化我的代码。例如,我曾经有过
<string name="cat">Cat</string>
<string name="cats">Cats</string>
Run Code Online (Sandbox Code Playgroud)
使用复数而不是多个字符串,我现在有了
<plurals name="cats">
<item quantity="<b>%d</b> one">Cat</item>
<item quantity="<b>%d</b> other">Cats</item>
</plurals>
Run Code Online (Sandbox Code Playgroud)
但是,我曾经检索字符串以编程方式在代码中使用。例如,
String text = context.getResources().getQuantityString(R.plurals.cats, 10);
textview.setText(Html.fromHtml(text));
Run Code Online (Sandbox Code Playgroud)
我想以粗体样式设置 10 值,但它没有设置粗体文本不包含粗体文本请帮助我如何存档此内容。
private ModelObject model;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
}
private void readFile() {
if (model == null) {
Gson gson = new Gson();
final String helpItem = “my _file.json”;
InputStream stream = null;
try {
stream = getResources().getAssets().open(helpItem);
Reader reader = new InputStreamReader(stream);
model = gson.fromJson(reader, ModelObjects.class);
reader.close();
stream.close();
} catch (IOException e) {
Timber.w(e);
} finally {
fileclose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我使用此代码的代码我正在从资产文件夹读取文件并解析为模型对象但我想在后台线程而不是主线程中读取此文件因此并获取数据主线程请建议我如何在后台实现读取文件线程并在主线程中获取值。
这是我的 xml:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/white"
android:paddingLeft="@dimen/cl_12"
android:paddingTop="@dimen/cl_48"
android:paddingRight="@dimen/cl_12"
android:paddingBottom="@dimen/cl_28">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/fingerprint_id"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_title"
style="@style/Typeface.Body.Bold.TextDarkGrey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_8"
android:lineSpacingExtra="4sp"
android:text="Enter your password"
app:layout_constraintTop_toBottomOf="@+id/imageView"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/tv_fingerprint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cl_16"
android:lineSpacingExtra="8sp"
android:text="Enter your Tesco password to activate fingerprint ID"
app:layout_constraintTop_toBottomOf="@+id/tv_title"
tools:ignore="MissingConstraints" />
<EditText
android:id="@+id/et_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cl_20"
android:ems="10"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintTop_toBottomOf="@+id/tv_fingerprint_description" />
<TextView …Run Code Online (Sandbox Code Playgroud)