現在、私はfragment_one.xml
に5 CardViews
を持っており、各カードには別のXMLページ(Lesson_One、Lesson_Twoなど)に行くボタンがあります。 )が、OneFragment.java
にあるコードでは、両方のボタンが開いていますLesson_Two
ボタンはすべてAndroidのフラグメントから同じアクティビティを開きます
どのように修正できますか?ここでは、効果的に第二の最初の意図を上書きし、二回intent
を代入している
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;
}
}
パーフェクト!ありがとう、私はそれを感謝の束! –