New tabs on button click/ delete tabs on button/add items to tab on button click

188 Views Asked by At

I am trying to make an application in Android studio in which user can create new tabs on a button click..like chrome, but the difference is they should be permanent unlike chrome tabs and only be deleted by the user on another button click, and I want to make these new tabs customizable so that user can also add new items in it. Until now I have made XML layout with tab layout and add deleted button, but I am new to android development and I am not sure what to do next, I learnt to add tabs statically by adding new fragment, but I have no idea how to make it dynamic so that user can add/delete new tabs.plz, any help appreciated...

.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>
0

There are 0 best solutions below