Q: Dynamically Add and Remove Views from Layout I'm working on one demo project in that I had create one XML file containing some views like ImageView, EditText. I'm loading this XML file on FrameLayout at runtime. At one point I want to remove all that views and again want to display them, I used removeView() method on button click but it does not work for me,,Please tell me the right way to do it..
       public class Demo extends Fragment implements OnClickListener, OnTouchListener{
    //Declaration of framelayout
    FrameLayout f;
    //Declaration of imageview
    ImageView imageview;
    View view, framelayoutview;
    File file;
    EditText etcardname, EditTextUserName,EditTextUsesrMobNumber,EditTextUsesrEmailID,EditTextUsesrAddress;
    TextView dialogtesting;
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.activity_modify_card ,container, false);
        framelayoutview = inflater.inflate(R.layout.frame_layout_data ,container, false);
        captureImageInitialization();
        Initialize();
        return view;
       }
     // Initialization of all views components
     private void Initialize() {
            f=(FrameLayout)view.findViewById(R.id.framelayout);
            Button btneditcardreset=(Button)view.findViewById(R.id.buttonresetcard);
            btneditcardreset.setOnClickListener(this);
            Bundle bundle = this.getArguments();
            int myInt;
            myInt = bundle.getInt("position");

            imageview=(ImageView)framelayoutview.findViewById(R.id.imageViewicon);
            EditTextUserName=(EditText)framelayoutview.findViewById(R.id.modifycardeditTextusername);
            EditTextUsesrMobNumber=(EditText)framelayoutview.findViewById(R.id.editTextmobilesnumber);
            EditTextUsesrEmailID=(EditText)framelayoutview.findViewById(R.id.editTextemailid);
            EditTextUsesrAddress=(EditText)framelayoutview.findViewById(R.id.editTextaddress);

            imageview.setOnTouchListener(this);
            EditTextUserName.setOnTouchListener(this);
            EditTextUsesrMobNumber.setOnTouchListener(this);
            EditTextUsesrEmailID.setOnTouchListener(this);
            EditTextUsesrAddress.setOnTouchListener(this);
            f.addView(framelayoutview);
           }
    @Override
    public void onClick(View v){
         if(v.getId()==R.id.buttonresetcard){
                 if(framelayoutview.getParent()!=null){
                 f.removeAllViews();
                 }
                 f.addView(framelayoutview);

                 }
      }

Sorry to all I forgot to tell that I provided OnTouchListener so that I can move the views anywhere in Layout. So when I press reset button all Views should get move back to their original location means where they were at on first load..

A: you can use 
imageview.setVisibility(View.GONE);
And
imageview.setVisibility(View.VISIBLE);
on particular event

A: If you had added your views dynamically to your FrameLayout then you can remove them.
Otherwise, if you showing your views from XML which are exist inside the frameLayout XML then you can't remove them but you can hide them from showing by setting setVisibility(View.GONE) or setVisibility(View.INVISIBLE).

A: Try this-
 @Override
    public void onClick(View v){
         if(v.getId()==R.id.buttonresetcard){
                 if(framelayoutview.getParent()!=null){
                 f.setVisibility(View.GONE);
                 }
                 f.addView(framelayoutview);

                 }
      }

