首页 > 解决方案 > 单击按钮时的新选项卡/删除按钮上的选项卡/单击按钮时将项目添加到选项卡

问题描述

我正在尝试在 Android Studio 中创建一个应用程序,在该应用程序中,用户可以在单击按钮时创建新选项卡......就像 chrome,但不同之处在于它们应该是永久性的,不像 chrome 选项卡,并且只能由用户在另一个按钮单击时删除,并且我想让这些新标签可自定义,以便用户也可以在其中添加新项目。到目前为止,我已经使用选项卡布局制作了 XML 布局并添加了已删除的按钮,但是我是 android 开发的新手,我不知道下一步该做什么,我学会了通过添加新片段来静态添加选项卡,但我不知道如何使其动态化,以便用户可以添加/删除新的 tabs.plz,任何帮助表示赞赏...

.java
package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TableLayout;

public class MainActivity extends AppCompatActivity {
    TableLayout tableLayout;
    Button button;
    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tableLayout.findViewById(R.id.tablayout);
        button.findViewById(R.id.button1);
        viewPager.findViewById(R.id.viewpager);
    }
} 
.Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
  <Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="Add routine"
      />
    </LinearLayout>
</LinearLayout>

标签: javascriptandroidandroid-tablayoutandroid-tabs

解决方案


推荐阅读