通过不同的活动在Fragement ViewPager中创建复选框

时间:2019-06-04 13:31:32

标签: java android xml

我正在尝试从待办事项列表应用程序的活动中创建一个复选框。

我已经创建了一个带有浮动操作按钮的Fragment View Pager,它为用户启动一个Activity以创建一个新任务,该任务在完成时显示为一个单击的复选框,将任务移至一个完整的View Pager选项卡。 / p>

下面是我的代码:

“片段”标签的XML代码

<RelativeLayout
    android:id="@+id/empty_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" >

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"> 
</android.support.v7.widget.RecyclerView>

    <TextView
        android:id="@+id/no_reminder_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:padding="16dp"
        android:gravity="center"
        android:text="Click on the + to create a new task" />

</RelativeLayout>

用于在“待办事项列表”中创建新项目的XML代码

<RelativeLayout 
 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=".MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:gravity="center"
    android:elevation="2dp"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ToolBarStyle"
    app:title="Create new task" />


<EditText
    android:id="@+id/newTask"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:hint="New Task"
    android:inputType="textCapSentences"
    android:layout_marginTop="100dp"
    android:layout_centerHorizontal="true" />

<Button
    android:id="@+id/newTaskButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Create"
    android:layout_marginTop="200dp"
    android:layout_centerHorizontal="true"/>

</RelativeLayout>

Java代码片段

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_tab1, container, false);

    TextView textView = (TextView) view.findViewById(R.id.newTask);
    String title= getActivity().getIntent().getStringExtra("title");
    textView.setText(title);

    return view;
}

0 个答案:

没有答案