Manipulate a tab fragment during runtime

46 Views Asked by At

I got three fragments each on a seperate Tab. On one tab I want to have a fragment in a card-style. One row should be like [ ________ ________ +]. After pressing the +Button I want a second identical row to appear. How could I achive that? What is a professional way to manipulate tagfragments during the runtime? How can I implement trancisions?

1

There are 1 best solutions below

0
On

I got it. I can add additional rows by:

@Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.imageButtonAdd:
            if(i==0){
                raiseCounterByOne();
                counter.setText(counterStart.toString());
                test = getActivity().findViewById(R.id.testView3);
                test.setVisibility(View.VISIBLE);
                i++;
            } else if(i==1){
                raiseCounterByOne();
                counter.setText(counterStart.toString());
                test = getActivity().findViewById(R.id.testView4);
                test.setVisibility(View.VISIBLE);
                i++;
            }
            break;
        case R.id.imageButtonCancel2:
            Log.d("","Close");
            test = getActivity().findViewById(R.id.testView3);
            test.setVisibility(View.GONE);
            i--;
            break;
        case R.id.imageButtonCancel3:
            Log.d("","Close");
            test = getActivity().findViewById(R.id.testView4);
            test.setVisibility(View.GONE);
            i--;
            break;
        default:
            break;
        }
    }

Is there a better way to be more flexible? Something like an array or a loop? I there a opportunity to put views into an array? I want to set a maximum number of rows that can be added. Furthermore I would like to index each row for later use.