Zainau
Zainau

Reputation: 93

Android Fragments?

I'm new to android and i'm following this guide to create a sliding tab with fragments. There are 3 tabs and 3 fragments created. However, I do not understand how can I start editing the individual fragments to do what I want.

Assume that I want the

Currently I have 3 java files:

Upvotes: 0

Views: 267

Answers (1)

Kristiyan Varbanov
Kristiyan Varbanov

Reputation: 2509

You can write you code logic in your onCreateView() or in onViewCreated() in every fragment.For example:

You have 2 textView in FirstFragment and one Button you can put your logic like this:

  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.yourXmlLayout, container, false);

        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

      //logic here
       yourButton = (Button)findViewById(R.id.yourButton);
       yourButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }

and so on... for SecondFragment and ThirdFragment.

Upvotes: 3

Related Questions