XML : Cannot update TextView and ProfilePictureView from Fragment

I'm trying to update a TextView and ProfilePictureView in a Fragment.

The activity should send the userId, and profileId to the fragment to update the textView and profilePictureView. It currently runs but doesn't update the textView and profilePictureView.

What I'm doing wrong?

FirstFragment.java:

  public class FirstFragment extends Fragment implements UserFragmentDetails  {        private ProfilePictureView profilePictureView;      private TextView textView;      private UserFragmentDetails userFragmentDetails;        @Override      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {          // return super.onCreateView(inflater, container, savedInstanceState);          View rootView = inflater.inflate(R.layout.first_fragment, container, false);          textView = (TextView)rootView.findViewById(R.id.textName);          profilePictureView = (ProfilePictureView)rootView.findViewById(R.id.profilePic);            return rootView;      }        @Override      public void onAttach(Context context) {          super.onAttach(context);          try{                userFragmentDetails = (UserFragmentDetails)context;          }          catch(ClassCastException ex) {              throw new ClassCastException(ex.toString());          }      }        @Override      public void setDetails(String userId, String name) {          textView.setText(name);          profilePictureView.setProfileId(userId);      }  }     

secondActivity.java:

  public class secondActivity extends AppCompatActivity implements UserFragmentDetails {     private Intent intent;      private Toolbar toolbar;      private String firstName, profileId;          @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_second);            intent = getIntent();          firstName = intent.getStringExtra("firstName");          profileId = intent.getStringExtra("Id");            toolbar = (Toolbar)findViewById(R.id.toolBar);          setSupportActionBar(toolbar);          toolbar.setLogo(R.drawable.ic_menu_image);          getSupportActionBar().setDisplayShowHomeEnabled(true);          getSupportActionBar().setDisplayShowTitleEnabled(false);   }        @Override      public boolean onCreateOptionsMenu(Menu menu) {          // Inflate the menu; this adds items to the action bar if it is present.          getMenuInflater().inflate(R.menu.menu_second, menu);          return true;      }        @Override      public boolean onOptionsItemSelected(MenuItem item) {          // Handle action bar item clicks here. The action bar will          // automatically handle clicks on the Home/Up button, so long          // as you specify a parent activity in AndroidManifest.xml.            switch(item.getItemId()) {              case android.R.id.home:                  Intent homeIntent = new Intent(this, secondActivity.class );                  homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);                  startActivity(homeIntent);          }          int id = item.getItemId();            //noinspection SimplifiableIfStatement          if (id == R.id.action_settings) {              return true;          }   return super.onOptionsItemSelected(item);      }        @Override      public void setDetails(String userId, String name) {          FirstFragment firstFragment = (FirstFragment)getSupportFragmentManager().findFragmentById(R.id.fragment1);            if(firstFragment !=null) {                firstFragment.setDetails(profileId, firstName);            }            else {                Bundle bundle = new Bundle();              bundle.putString("firstName", firstName);              bundle.putString("profileId", profileId);              FirstFragment firstFragment1 = new FirstFragment();              firstFragment1.setArguments(bundle);                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();              fragmentTransaction.replace(R.id.fragment1, firstFragment1);              fragmentTransaction.commit();          }      }    

first_fragment.xml:

      <?xml version="1.0" encoding="utf-8"?>  <LinearLayout      xmlns:android="http://schemas.android.com/apk/res/android"      android:orientation="vertical"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:id="@+id/fragmentPic">        <TextView          android:id="@+id/textName"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:text="@string/users_FirstName"          android:textSize="@dimen/font_size"          android:layout_gravity="center_horizontal"/>        <com.facebook.login.widget.ProfilePictureView          android:id="@+id/profilePic"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_gravity="center_horizontal"          >      </com.facebook.login.widget.ProfilePictureView>    </LinearLayout>    

activity_second.xml:

  <LinearLayout          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"          android:orientation="vertical"          android:background="@color/backgroundColor"           >      <include android:id="@+id/toolBar"          layout="@layout/toolbar" />          <android.support.v4.widget.DrawerLayout            android:layout_width="match_parent"            android:layout_height="match_parent">              <fragment                android:layout_width="match_parent"                android:layout_height="match_parent"                tools:layout="@layout/first_fragment"                class="edu.sjsu.cmpe277.termproject.Fragments.FirstFragment"                android:id="@+id/fragment1"                />          </android.support.v4.widget.DrawerLayout>    </LinearLayout>    

No comments:

Post a Comment