我已经学会了如何在按钮点击时从一个片段活动更改到另一个(所有都是片段活动),但现在我在同一片段上有多个按钮的问题。只有第一个按钮ID有效。我有多个按钮,每个按钮都有不同的片段活动。需要帮助。
package com.test.fragmentation;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class List extends Fragment {
public List() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_list, container, false);
Button ID = (Button) rootView.findViewById(R.id.btnHello);
ID.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
HelloFragment NAME = new HelloFragment();
fragmentTransaction.replace(R.id.fragment_container, NAME);
fragmentTransaction.commit();
}
});
return rootView;
}
}