I am developing the following application in android Studio-
    **user on entering todo  and click add button, it Should add to linear layout with checkbox which 
    is helpful to delete todos.**
my idea: I created a new XML file with textView and CheckBox in single_item.xml  and inflate it to  
         linearlayout which is present in main xml  as shown in 
          below.............................................
problem:  when I clicked the add button , app crashes. 
           I found that this issue is because I added textview.setText(text)  in  java code.
            if I had not added this line , then sample single_element.xml is getting added 
                 LinearLayout.But I needed to content of textview to be set to input 
                 that is given by user in editText as shown.
     I had deleted Most of the code in xml file because Stackoverflow is showing me "It looks like your post is mostly code; please add some more details." ""...............................................
          ..................................................................................................................................................................................................................................................................................................................................................................................
[activity_main.xml][1]
[single_element.xml][2]
[1]: https://i.stack.imgur.com/UhtGJ.png
[2]: https://i.stack.imgur.com/Pcu1O.png
In activity_main.xml I had LinearLayout,editText View,Add Button and delete button.
LinearLayout  -> id="@+id/linearLayout"
    
EditText        -> android:id="@+id/edit"
<Button        ->android:id="@+id/add_button"
    
single_element.xml
TextView     ->id="@+id/textView"
   
CheckBox    ->id="@+id/checkBox"
    
MainActivity.java
    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
            EditText editText = (EditText) findViewById(R.id.edit);
            String text = editText.getText().toString().trim();
            TextView textView = (TextView) findViewById(R.id.textView);
            textView.setText(text);
            LayoutInflater inflater = getLayoutInflater();
            View view = inflater.inflate(R.layout.single_element,null);
            linearLayout.addView(view);
        }
    });
   
Thanks in Advance.................................................................................................................................................................................................................................................................................................................................................................................................
 
    