I have onclicklistener that works. I am trying to launch a new fragment from the button click on the list view. Right now, the fragment does not launch. However, the emulator we are using does not crash, so if we're understanding this correctly, it isn't connecting to the new fragment/XML page.
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l)
{
myBadData.setId(i);
Fragment fr = new event_description();
//fr.setArguments(bundle);
FragmentManager fm = getFragmentManager();
FragmentTransaction fragmentTransaction = fm.beginTransaction();
//int contId = v.getId();
fragmentTransaction.add(R.id.page, fr);
// fragmentTransaction.add(view.getId(), fr);
// fragmentTransaction.commit();
Intent intent =new Intent(eventList.this, fr.getClass());
}
Here is our XML code for the view that we are trying to add the fragment over top of.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/page"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.alex.qtapandroid.ui.fragments.DayFragment">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
<ListView
android:id="@+id/dayList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
You should be using
commit()
to start your transaction, not anIntent()
, you also want to usereplace()
notadd()
:change this line
to:
and better replace fragment in container ,