我需要在一个名为ActivityCard
的片段中看到的活动详细信息,以便从另一个名为Timesheet
的片段中看到。这个想法是为了让使用我正在开发的应用程序的人看到他们在应用程序的ActivityCard
片段中键入的活动细节,以查看他们在Timesheet
片段中所做的格式。我以前从来没有在Android Studio中做过这样的事情,所以任何帮助都将不胜感激。fragment_activity_card.xml
:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".Fragments.ActivityCard">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="139dp"
android:layout_gravity="top"
android:layout_margin="40dp"
android:orientation="vertical">
<TextView
android:id="@+id/activity_card_title"
android:layout_width="133dp"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Debugging App"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.086"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/imageView"
android:layout_width="120dp"
android:layout_height="100dp"
android:layout_alignParentStart="true"
android:layout_gravity=""
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:background="@drawable/bug"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/startEndTimes"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:text="13:00 -> 14:00"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/activityDate" />
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="1h 0m"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<TextView
android:id="@+id/activityDate"
android:layout_width="129dp"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginStart="20dp"
android:layout_marginTop="12dp"
android:text="Mon 23 May 2023"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/activity_card_title" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
fragment_timesheet.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:text="Activity" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView11"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="Date of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView13"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="End of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:text="Activity" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView10"
android:layout_width="88dp"
android:layout_height="match_parent"
android:text="Date of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category" />
</TableRow>
</TableLayout>
<TextView
android:id="@+id/textView20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:text="Activity" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView21"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:text="Date of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView23"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End of Task" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Category" />
</TableRow>
</TableLayout>
</LinearLayout>
1条答案
按热度按时间eagi6jfj1#
是的,你可以在fragment中添加fragment并在Android中查看它,你需要使用getChildFragmentManager在接口中添加fragment,以便在fragment之间进行数据通信。
这是它在ParentFragment onViewCreated片段中的外观
片段管理器子片段