目前我有一个fragment_one.xml
其上有5 CardViews
,并且每个卡片上都有一个Button,用于分离XML页面(Lesson_One,Lesson_Two等等...) )但与我在OneFragment.java
代码,这两个按钮都是开放的Lesson_Two
按钮都从一个Android片段打开相同的活动
我该如何解决这个问题?这里是我的代码
FragmentOne.java
public class OneFragment extends Fragment{
Intent intent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_one, container, false);
intent = new Intent(getActivity(), LessonOne.class);
final Button button = (Button) root.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(intent);
}
});
intent = new Intent(getActivity(), LessonTwo.class);
final Button button2 = (Button) root.findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(intent);
}
});
return root;
}
}
完美!谢谢一堆,我感谢它! –