Как добавить вторую строку текстового представления из другой позиции

#java #android #textview

Вопрос:

Я работаю над приложением здесь, где необходимо заполнить некоторые пользовательские данные. Затем данные необходимо поместить в другое действие, каждое из которых уникально TextViews . Вот мой пользовательский интерфейс активности

введите описание изображения здесь

Вот мой 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"
    tools:context=".PreviewActivity">

    <TextView
        android:id="@ id/textView4"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="20dp"
        android:text="Name:"
        android:textSize="16sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    <View
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="#3F230D"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView4"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@ id/textView5"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Phone num:"
        android:textSize="16sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@ id/textView4"
        app:layout_constraintTop_toBottomOf="@ id/textView4"
        app:layout_constraintVertical_bias="0.0" />

    <View
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="#3F230D"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView5"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@ id/textView9"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Date:"
        android:textSize="16sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@ id/textView8"
        app:layout_constraintTop_toBottomOf="@ id/textView8"
        app:layout_constraintVertical_bias="0.0" />

    <View
        android:id="@ id/view"
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="#3F230D"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView9"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@ id/textView6"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Kind of order:"
        android:textSize="16sp"
        android:textStyle="bold"

        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@ id/textView5"
        app:layout_constraintTop_toBottomOf="@ id/textView5"
        app:layout_constraintVertical_bias="0.0" />

    <View
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="#3F230D"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView6"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@ id/textView7"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Price:"
        android:textSize="16sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@ id/textView6"
        app:layout_constraintTop_toBottomOf="@ id/textView6"
        app:layout_constraintVertical_bias="0.065" />

    <View
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="#3F230D"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView7"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@ id/textView8"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Deposit:"
        android:textSize="16sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="@ id/textView7"
        app:layout_constraintTop_toBottomOf="@ id/textView7"
        app:layout_constraintVertical_bias="0.0" />

    <View
        android:layout_width="0dp"
        android:layout_height="2dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="2dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:background="#3F230D"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@ id/textView8"
        app:layout_constraintVertical_bias="0.0" />

    <TextView
        android:id="@ id/tv_name"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:text="Jett Kavinsky"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="@ id/textView4"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@ id/textView4"
        app:layout_constraintTop_toTopOf="@ id/textView4" />

    <TextView
        android:id="@ id/tv_number"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:text="077364063"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="@ id/textView5"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@ id/textView5"
        app:layout_constraintTop_toTopOf="@ id/textView5" />

    <TextView
        android:id="@ id/tv_kind"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:text="Some text here"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="@ id/textView6"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@ id/textView6"
        app:layout_constraintTop_toTopOf="@ id/textView6" />

    <TextView
        android:id="@ id/tv_price"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:text="150000"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="@ id/textView7"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@ id/textView7"
        app:layout_constraintTop_toTopOf="@ id/textView7" />

    <TextView
        android:id="@ id/tv_deposit"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:text="20000"
        android:textSize="16sp"
        app:layout_constraintBottom_toBottomOf="@ id/textView8"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@ id/textView8"
        app:layout_constraintTop_toTopOf="@ id/textView8" />

    <TextView
        android:id="@ id/tv_date"
        style="@style/TextAppearance.AppCompat.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:text="04․08․2021"
        android:textSize="16sp"

        app:layout_constraintBottom_toBottomOf="@ id/textView9"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@ id/textView9"
        app:layout_constraintTop_toTopOf="@ id/textView9" />

</androidx.constraintlayout.widget.ConstraintLayout>
 

3-м параметром должен быть текст в две строки, но вторая строка должна начинаться с «вида порядка», а не с «какой-то текст здесь» (как это происходит под «какой-то текст здесь» прямо сейчас). Как я могу это изменить? Спасибо вам заранее.

Комментарии:

1. Можете ли вы опубликовать свой XML и то, что вы в настоящее время пробовали ? Спасибо

Ответ №1:

Вы можете использовать n для новой строки, как это:

 android:text="textnmore text"