Я новичок в Android и борюсь с моим проектом фрагментов, PLS помочь мне! здесь я не могу заменить фрагмент по умолчанию (содержащий три кнопки) на другие фрагменты, используя событие нажатия кнопки. пс: => проблема: мой код работает отлично и компилирует тоже, но кнопка не отвечает вот мой кодЯ не могу заменить свой фрагмент по умолчанию (домашний фрагмент) на другие фрагменты с помощью события click click?
activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_container"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="ABOUT ME"
android:id="@+id/bttn_about"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="MY SKILLS"
android:id="@+id/bttn_skills"
android:layout_gravity="center_horizontal" />
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="CONTACT ME"
android:layout_below="@+id/bttn_skills"
android:layout_gravity="center_horizontal" />
</LinearLayout>
и вот мой файл Java.
mainActivity.java
общественного класса MainActivity расширяет AppCompatActivity {
Button bttn_about,bttn_skills,bttn_contact;
FragmentTransaction fragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.main_container,new HomeFragment());
fragmentTransaction.commit();
bttn_about=(Button)findViewById(R.id.bttn_about);
bttn_skills=(Button)findViewById(R.id.bttn_skills);
bttn_contact=(Button)findViewById(R.id.bttn_contact);
bttn_about.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//FragmentManager,Fragment Transaction..... same as above code
}
});
}
и вот второй фрагмент
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.AboutmeFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/aboutme"
android:id="@+id/textView2"
android:layout_gravity="left|top" />
</RelativeLayout>
</FrameLayout>
У вас появились сообщения об ошибках? – Masum
нет сообщений об ошибках, не удалось щелкнуть по кнопке. :( – sudheer