Hello i am trying to load my fragment into an activity but cannot get it to load. Please could someone tell me what i did wrong. My toolbar resides in activity but my fragment contains a textview and profilepictureview from facebook. What am i missing as i am not able to display the textview and profilepicture view
Below is my 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:hint="JJJJ" 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" android:name="edu.sjsu.cmpe277.termproject.Fragments.FirstFragment" android:id="@+id/fragment1" /> </android.support.v4.widget.DrawerLayout> </LinearLayout>
toolbar.xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:local="http://schemas.android.com/apk/res-auto" android:id="@+id/toolBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:background="@color/colorPrimary" android:elevation="5dp" android:gravity="top|start"> </android.support.v7.widget.Toolbar>
FirstFragment.java:
public class FirstFragment extends Fragment { private ProfilePictureView profilePictureView; private TextView textView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return super.onCreateView(inflater, container, savedInstanceState); View rootView = inflater.inflate(R.layout.event_fragment, container, false); textView = (TextView)rootView.findViewById(R.id.textName); profilePictureView = (ProfilePictureView)rootView.findViewById(R.id.profilePic); return rootView; }
secondActivity.java:
public class secondActivity extends AppCompatActivity { private Intent intent; private Toolbar toolbar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); intent = getIntent(); String firstName = intent.getStringExtra("firstName"); String userId = 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. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }
}
No comments:
Post a Comment