I am currently in the lab and I am getting a weird error. Everything compiles fine, and the application works fine, but when I click on the name, it shows the twitter channel, but also shows the names of people, as when overlaying one view on top of another.
Here is my code for MainActivity:
package course.labs.fragmentslab;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity implements
FriendsFragment.SelectionListener {
private static final String TAG = "Lab-Fragments";
private FriendsFragment mFriendsFragment;
private FeedFragment mFeedFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
if (!isInTwoPaneMode()) {
mFriendsFragment = new FriendsFragment();
FragmentManager fragM = getFragmentManager();
FragmentTransaction fragT = fragM.beginTransaction();
fragT.add(R.id.fragment_container, mFriendsFragment);
fragT.commit();
} else {
mFeedFragment = (FeedFragment) getFragmentManager()
.findFragmentById(R.id.feed_frag);
}
}
private boolean isInTwoPaneMode() {
return findViewById(R.id.fragment_container) == null;
}
public void onItemSelected(int position) {
Log.i(TAG, "Entered onItemSelected(" + position + ")");
if (mFeedFragment == null)
mFeedFragment = new FeedFragment();
if (!isInTwoPaneMode()) {
FragmentManager fragM = getFragmentManager();
FragmentTransaction fragT = fragM.beginTransaction();
fragT.add(R.id.fragment_container ,mFeedFragment);
fragT.commit();
getFragmentManager().executePendingTransactions();
}
mFeedFragment.updateFeedDisplay(position);
}
}
Here is the corresponding XML file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" /
As I said, everything works fine, but the activity saves one fragment, and then displays another fragment.
I have no idea why.
source
share