Cannot resolve symbol in (RecyclerView)findViewById(R.id.xxx) - android

I want to create a food menu using RecycleView by connecting to firebase, I have declared recycler_menu as variable, but when i type recycler_menu = (RecyclerView)findViewById(R.id.recycler_menu); there are error showing cannot resolve symbol R.id.recycler_menu. Need help on solving this error.I have added implementation 'com.android.support:recyclerview-v7:27.1.1' support library but still unable to solve this error.
Home.java
package com.example.liew.idelivery;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import com.example.liew.idelivery.Common.Common;
import com.example.liew.idelivery.Interface.ItemClickListener;
import com.example.liew.idelivery.Model.Category;
import com.example.liew.idelivery.ViewHolder.MenuViewHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
public class Home extends AppCompatActivity implements
NavigationView.OnNavigationItemSelectedListener {
FirebaseDatabase database;
DatabaseReference category;
TextView txtFullName;
RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Menu");
setSupportActionBar(toolbar);
//Init Firebase
database = FirebaseDatabase.getInstance();
category = database.getReference("Category");
TextView txtFullName;
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//set name for user
View headerView = navigationView.getHeaderView(0);
txtFullName = (TextView)headerView.findViewById(R.id.txtFullName);
txtFullName.setText(Common.currentUser.getName());
// Load menu
recycler_menu = (RecyclerView)findViewById(R.id.recycler_menu);
recycler_menu.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);
loadMenu();
}
private void loadMenu() {
FirebaseRecyclerAdapter<Category,MenuViewHolder> adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(Category.class,R.layout.menu_item,MenuViewHolder.class,category){
#Override
protected void populateViewHolder(MenuViewHolder viewHolder, Category model, int position) {
viewHolder.txtMenuName.setText(model.getName());
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.imageView);
final Category clickItem = model;
viewHolder.setItemClickListener(new ItemClickListener() {
#Override
public void onClick(View view, int position, boolean isLongClick) {
Toast.makeText(Home.this,""+clickItem.getName(), Toast.LENGTH_SHORT).show();
}
});
}
};
recycler_menu.setAdapter(adapter);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_menu) {
// Handle the camera action
} else if (id == R.id.nav_cart) {
}else if (id == R.id.nav_orders) {
}else if (id == R.id.nav_logout) {
}else if (id == R.id.nav_share) {
}else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
MenuViewHolder.java
package com.example.liew.idelivery.ViewHolder;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.liew.idelivery.Interface.ItemClickListener;
import com.example.liew.idelivery.R;
public class MenuViewHolder extends RecyclerView.ViewHolder implements
View.OnClickListener {
public TextView txtMenuName;
public ImageView imageView;
private ItemClickListener itemClickListener;
public MenuViewHolder(View itemView){
super(itemView);
txtMenuName = (TextView)itemView.findViewById(R.id.menu_name);
imageView = (ImageView)itemView.findViewById(R.id.menu_image);
itemView.setOnClickListener(this);
}
public void setItemClickListener(ItemClickListener itemClickListener){
this.itemClickListener = itemClickListener;
}
#Override
public void onClick(View view){
itemClickListener.onClick(view,getAdapterPosition(),false);
}
}
menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardElevation="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/menu_image"
android:scaleType="centerCrop"
android:src="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/menu_name"
android:text="Name of Menu"
android:textAlignment="center"
android:textColor="#android:color/white"
android:background="#4f0e0d0e"
android:textSize="20sp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</android.support.v7.widget.CardView>
activity_home.xml
<?xml version="1.0" encoding="utf-8"?
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#drawable/background"
tools:openDrawer="start">
<include
layout="#layout/app_bar_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_home"
android:background="#color/overlayBackground"
app:itemTextColor="#android:color/white"
app:itemIconTint="#android:color/white"
app:menu="#menu/activity_home_drawer" />
</android.support.v4.widget.DrawerLayout>
menu_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="200dp"
app:cardElevation="4dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/menu_image"
android:scaleType="centerCrop"
android:src="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/menu_name"
android:text="Name of Menu"
android:textAlignment="center"
android:textColor="#android:color/white"
android:background="#4f0e0d0e"
android:textSize="20sp"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
content_home.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".Home"
tools:showIn="#layout/app_bar_home">
<android.support.v7.widget.RecyclerView>
android:id="#+id/recycler_menu"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>

Try this in your content_home.xml:
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_menu"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
What is wrong with your code is the > character is placed in the wrong position, your original code:
<android.support.v7.widget.RecyclerView>
android:id="#+id/recycler_menu"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
</android.support.v7.widget.RecyclerView>

findViewById searches for the ID "recycler_menu" in the xml-files.
This error appears if there is no ID like this in your xml-files.
As I see it right this ID isn't implemented in your XML-File. Maybe you have some more xml-Files where it is implemented? Please show the xml file where this ID is implemented

if you want to claim
recycler_menu =(RecyclerView)findViewById(R.id.recycler_menu);
You should create a xml file like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
`

Code for getting reference is perfectly alright
recycler_menu = (RecyclerView)findViewById(R.id.recycler_menu);
Go to XML of activity_home and re-confirm that recyclerview has id with name
recycler_menu
like this
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
for more help kindly send XML of activity_home

Related

Action(Click) is working on layout xml file with NavigationView(Navigation drawer) implementation

Implemented navigation drawer but action(click) is not happening on home dashboard(ContentMain.xml), referring below example.
https://www.tutorialspoint.com/navigationview-in-actionbar-in-android
content_main.xml has a button but click is happening and navigation working fine.
Find the below code
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
app_bar_main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
MainActivity.java
package com.example.andy.myapplication;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/app_bar_main">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/nextPageBtn"/>
</android.support.constraint.ConstraintLayout>
ContentMain.java
package com.example.andy.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;
public class ContentMain extends AppCompatActivity {
public static final String TAG = MainActivity.class.getSimpleName();
private Button nextPageBtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_main);
System.out.println("here");
nextPageBtn = findViewById(R.id.nextPageBtn);
nextPageBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("Clicked");
Intent intent = new Intent(ContentMain.this, NextPage.class);
//Toast.makeText(this, "Clicked item one", Toast.LENGTH_SHORT).show();
startActivity(intent);
}
});
}
}
Check your content_main.xml file tools:context=".MainActivity"
You should call your button listener in your MainActivity.

Using AndroidStudio emulation On_Click Events within fragments firing when using tab and enter key but not mouse click

I have a problem within my code that seems to me as it is working but only in the given situation where On_Click Events within fragments are firing when using tab and enter key but not mouse click. I am using the emulator through android studio SDK23 for the emulater. When I test it on my phone sdk26 it does not allow the tap to click anything within the fragment. I feel like I may be missing something very simple.
Here is my Activity:
package com.wgu.c196.testproject;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.wgu.c196.testproject.database.TermDatabase;
import com.wgu.c196.testproject.fragment.TestFragment;
public class MainActivity extends AppCompatActivity implements
NavigationView.OnNavigationItemSelectedListener,
TestFragment.OnListFragmentInteractionListener{
private DrawerLayout drawer;
private FloatingActionButton fab;
private TextView fragTitle;
public DrawerLayout getDrawer() {
return drawer;
}
public void setDrawer(DrawerLayout drawer) {
this.drawer = drawer;
}
public TextView getFragTitle() {
return fragTitle;
}
public void setFragTitle(TextView fragTitle) {
this.fragTitle = fragTitle;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Fragment testFragment = new TestFragment();
replaceFragment(testFragment );
fragTitle = findViewById(R.id.fragment_title);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#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_main, 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);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
item.setChecked(true);
drawer.closeDrawers();
fab.show();
switch(item.getItemId()) {
case R.id.nav_terms:
case R.id.nav_courses:
case R.id.nav_assessment:
case R.id.nav_scheduler:
case R.id.nav_alerts:
case R.id.nav_share:
case R.id.nav_send:
default:
}
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
#Override
public void onDestroy(){
TermDatabase.destroyInstance();
super.onDestroy();
}
public void replaceFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager();
// Begin the transaction
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_main_placeholder, fragment, fragment.toString());
fragmentTransaction.addToBackStack(fragment.toString());
fragmentTransaction.commit();
}
#Override
public void onListFragmentInteraction(View view) {
}
}
My Fragment:
package com.wgu.c196.testproject.fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import com.wgu.c196.testproject.MainActivity;
import com.wgu.c196.testproject.R;
public class TestFragment extends Fragment {
// TODO: Customize parameter argument names
private static final String ARG_COLUMN_COUNT = "column-count";
// TODO: Customize parameters
private int mColumnCount = 1;
private OnListFragmentInteractionListener mListener;
private View mView;
public View getView() {
return mView;
}
public void setView(View mView) {
this.mView = mView;
}
ragment (e.g. upon screen orientation changes).
*/
public TestFragment() {
}
// TODO: Customize parameter initialization
#SuppressWarnings("unused")
public static TestFragment newInstance(int columnCount) {
TestFragment fragment = new TestFragment();
Bundle args = new Bundle();
args.putInt(ARG_COLUMN_COUNT, columnCount);
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_test, container, false);
((MainActivity) mView.getContext()).getFragTitle().setText("Test Button");
Button btn = mView.findViewById(R.id.d_button_id);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "Something clicked me in Fragment!", Toast.LENGTH_SHORT).show();
}
});
btn.setOnTouchListener(new View.OnTouchListener() {
#Override public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(v.getContext(), "Something touched me in Fragment!", Toast.LENGTH_SHORT).show();
return false;
}
});
return mView;
}
#Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnListFragmentInteractionListener) {
mListener = (OnListFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnListFragmentInteractionListener");
}
}
#Override
public void onDetach() {
super.onDetach();
mListener = null;
}
#Override
public void onDestroy(){
super.onDestroy();
}
public interface OnListFragmentInteractionListener {
// TODO: Update argument type and name
void onListFragmentInteraction(View view);
}
}
My main layout activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/top_margin"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/global_top_margin"
android:theme="#style/AppTheme.AppBarOverlay">
<TextView
android:id="#+id/fragment_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:textSize="14sp"
android:textStyle="bold" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_main_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_fragment_top_margin"
android:clickable="true"
android:scrollbars="vertical"
></FrameLayout>
<include layout="#layout/nav_menu_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/ic_action_add_entity"/>
</android.support.design.widget.CoordinatorLayout>
My fragment layout fragment_test.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:id="#+id/term_list_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:clickable="true">
<Button
android:id="#+id/d_button_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:text="My Button to Click"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:textAppearance="?android:textAppearanceLarge" />
</LinearLayout>
Ultimately I fixed my own problem. Which was started by choosing Navigation Activity when first starting my project.
I removed
<include layout="#layout/nav_menu_main" />
from my activity_main.xml then restructured it whith the xml from nav_menu_main, using DrawerLayout as the Parent and CoordinatorLayout from activity_main.xml as the child.
I consulted this stack Overflow which lead me to my fix.
Drawer Layout Overlapping | Covering complete space in Fragment
My new activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/top_margin"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/global_top_margin"
android:theme="#style/AppTheme.AppBarOverlay">
<TextView
android:id="#+id/fragment_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:textSize="14sp"
android:textStyle="bold" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/content_main_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/main_fragment_top_margin"
android:clickable="true"
android:scrollbars="vertical"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/ic_action_add_entity"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>

Switching between fragments with a button in default Navigation Drawer template of Android Studio

I'm using default Navigation Drawer in Android Studio, and I added two fragments for first two button in navigation drawer. Everything works fine and I can switch between these fragments from drawer menu.
But I want to have a simple button in first fragment that clicking on it take me to second fragment. Clicking on such button opens second fragment but it seems to overlap whole screen and disappear the navigation view.
These are my project's codes:
MainActivity.java :
package com.example.arantik.test4;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
Fragment fragment=null;
if (id == R.id.nav_camera) {
fragment=new Fragment_1();
} else if (id == R.id.nav_gallery) {
fragment=new Fragment_2();
}
android.support.v4.app.FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.mainFrame, fragment);
transaction.addToBackStack(null);
transaction.commit();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
content_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.arantik.test4.MainActivity"
tools:showIn="#layout/app_bar_main">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainFrame">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
Fragment_1.java :
package com.example.arantik.test4;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class Fragment_1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_1_layout, container, false);
Button button=(Button)view.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
android.support.v4.app.FragmentManager fragmentManager = getFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment_2 fragment_2=new Fragment_2();
fragmentTransaction.replace(android.R.id.content, fragment_2);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
return view;
}
}
fragmen_1_layout.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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:text="First Fragment"
android:textSize="20sp"/>
<Button
android:layout_width="100dp"
android:layout_height="60dp"
android:id="#+id/button"
android:text="click"/>
</LinearLayout>
Fragment_2.java :
package com.example.arantik.test4;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment_2 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_2_layout, container, false);
return view;
}
}
fragmen_2_layout.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:background="#00ff00">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:text="Second Fragment"
android:textSize="20sp"/>
</LinearLayout>
I've not changed other Java or XML codes.
Add a public method to MainActivity, cast getActivity() to MainActivity in your fragment, and then you can invoke the method. You can also use interface, refer Communicating with Other Fragments

Navigation drawer on all activities

I have two activities the first one is 'Navigation drawer activity' (MainActivity) and the second activity I have created is a 'Tabbed activity' (OverView). How can I add Navigation drawer menu on Tabbed activity.
Your help and suggestion are very helpful.
Thanks
Rao
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.raoburugula.mytable.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.raoburugula.mytable.MainActivity"
tools:showIn="#layout/app_bar_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
nav_header_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="#dimen/nav_header_height"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
app:srcCompat="#android:drawable/sym_def_app_icon" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:text="Android Studio"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="android.studio#android.com" />
</LinearLayout>
MainActivity.java
package com.raoburugula.mytable;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton)
findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open,
R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView)
findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.overview) {
Intent overviewIntent = new Intent(getApplicationContext(),
OverView.class);
startActivity(overviewIntent);
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Overview activity where I want navigation menu is
activity_over_view.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.raoburugula.mytable.OverView">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
fragment_over_view.xml
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.raoburugula.mytable.OverView$PlaceholderFragment">
<TextView
android:id="#+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
OverView.Java
package com.raoburugula.mytable;
import android.support.design.widget.TabLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class OverView extends AppCompatActivity {
/**
* The {#link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {#link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {#link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {#link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_over_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new
SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
FloatingActionButton fab = (FloatingActionButton)
findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action",
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
#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_over_view, 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);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
public PlaceholderFragment() {
}
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_over_view,
container, false);
TextView textView = (TextView)
rootView.findViewById(R.id.section_label);
textView.setText(getString(R.string.section_format,
getArguments().getInt(ARG_SECTION_NUMBER)));
return rootView;
}
}
/**
* A {#link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class
below).
return PlaceholderFragment.newInstance(position + 1);
}
#Override
public int getCount() {
// Show 3 total pages.
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "SECTION 1";
case 1:
return "SECTION 2";
case 2:
return "SECTION 3";
}
return null;
}
}
}
Right click anywhere in your project tab in left sidebar, choose New -> Activity -> Navigation Drawer Activity
then modify content_main.xml, add the following
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/view_pager">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/tab_layout"/>
</android.support.v4.view.ViewPager>
You are done well so far except one thing. Instead of using Intent overviewIntent = new Intent(getApplicationContext(), OverView.class); you need to create OverView class as fragment and attache it existing MainActivity. You are done.

No view found for id 0x7f0c0071

I really tried to find something here that solves this problem but I didn't find anything...
MainActivity.java:
package de.thejakekols.brunoflo.teamgennewsql;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.HeaderViewListAdapter;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
SQLHelper db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
db = new SQLHelper(this);
addItemsFromDb();
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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.addUserMenu) {
// AddUser addStudent = new AddUser();
// FragmentManager manager = getSupportFragmentManager();
// manager.beginTransaction().replace(R.id.content_main, addStudent).addToBackStack(null).commit();
getSupportFragmentManager().beginTransaction().add(R.id.content_main, new AddClass()).commit();
return true;
}else if(id == R.id.addClassMenu){
AddClass addClass = new AddClass();
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.content_main, addClass).addToBackStack(null).commit();
return true;
}
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void addItemsFromDb() {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
final Menu menu = navigationView.getMenu();
ArrayList<String> klassen = db.getAllKlassen();
for (int i = 0; i < klassen.size(); i++) {
menu.add(klassen.get(i));
}
// refreshing navigation drawer adapter
for (int i = 0, count = navigationView.getChildCount(); i < count; i++) {
final View child = navigationView.getChildAt(i);
if (child != null && child instanceof ListView) {
final ListView menuView = (ListView) child;
final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
wrapped.notifyDataSetChanged();
}
}
}
}
And my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
And my app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="de.thejakekols.brunoflo.teamgennewsql.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main"
android:id="#+id/include" />
</android.support.design.widget.CoordinatorLayout>
And my content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="de.thejakekols.brunoflo.teamgennewsql.MainActivity"
tools:showIn="#layout/app_bar_main">
</RelativeLayout>
And i'll only provide my AddUser.java, because the AddClass.java is nearly the same:
package de.thejakekols.brunoflo.teamgennewsql;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.ArrayList;
/**
* A simple {#link Fragment} subclass.
*/
public class AddUser extends Fragment {
public AddUser() {
// Required empty public constructor
}
EditText vorname, nachname;
Button addstudent;
Spinner spinner;
SQLHelper db;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_add_user, container, false);
vorname = (EditText) view.findViewById(R.id.vorname);
nachname = (EditText) view.findViewById(R.id.nachname);
addstudent = (Button) view.findViewById(R.id.addStudent);
spinner = (Spinner) view.findViewById(R.id.spinner);
db = new SQLHelper(getActivity());
ArrayList<String> spinnerArray = db.getAllKlassen();
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, spinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerArrayAdapter);
addstudent.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
vorname.setText("");
nachname.setText("");
if(db.addStudent(spinner.getSelectedItem().toString(), vorname.getText().toString(), nachname.getText().toString()) == true){
Toast.makeText(getContext(), "Der Benutzer " + vorname.getText().toString() + " " + nachname.getText().toString() + " wurde erfolgreich der Klasse " + spinner.getSelectedItem().toString() + " hinzugefügt", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getContext(), "Da ist was schief gelaufen!", Toast.LENGTH_LONG).show();
}
}
});
return view;
}
}
my fragment_adduser.xml:
<RelativeLayout 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="de.thejakekols.brunoflo.teamgennewsql.AddUser"
android:id="#+id/addStudentFragment">
<!-- TODO: Update blank fragment layout -->
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:id="#+id/vorname"
android:hint="Vorname" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_below="#+id/vorname"
android:layout_alignParentStart="true"
android:id="#+id/nachname"
android:hint="Nachname" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/nachname"
android:layout_alignParentStart="true"
android:id="#+id/spinner" />
<Button
android:text="Schüler hinzufügen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner"
android:layout_alignParentEnd="true"
android:id="#+id/addStudent" />
</RelativeLayout>
I also tried it with a fresh fragment but it didn't worked aswell :(
Logcat Log:
12-1012:16:12.4904371-4371/de.thejakekols.brunoflo.teamgennewsqlE/FragmentManager:Noviewfoundforid0x7f0c0071(de.thejakekols.brunoflo.teamgennewsql:id/content_main)forfragmentAddClass{560ed4#0id=0x7f0c0071}
12-1012:16:12.4904371-4371/de.thejakekols.brunoflo.teamgennewsqlE/FragmentManager:Activitystate:
12-1012:16:12.4914371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:LocalFragmentActivity3469381State:
12-1012:16:12.4914371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mCreated=truemResumed=truemStopped=falsemReallyStopped=false
12-1012:16:12.4914371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mLoadersStarted=true
12-1012:16:12.4914371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:ActiveFragmentsin921187d:
12-1012:16:12.4914371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:#0:AddClass{560ed4#0id=0x7f0c0071}
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mFragmentId=#7f0c0071mContainerId=#7f0c0071mTag=null
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mState=1mIndex=0mWho=android:fragment:0mBackStackNesting=1
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mAdded=truemRemoving=falsemFromLayout=falsemInLayout=false
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mHidden=falsemDetached=falsemMenuVisible=truemHasMenu=false
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mRetainInstance=falsemRetaining=falsemUserVisibleHint=true
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mFragmentManager=FragmentManager{921187dinHostCallbacks{63bb372}}
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mHost=android.support.v4.app.FragmentActivity$HostCallbacks#63bb372
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:AddedFragments:
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:#0:AddClass{560ed4#0id=0x7f0c0071}
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:BackStackIndices:
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:#0:BackStackEntry{44453c3#0}
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:FragmentManagermiscstate:
12-1012:16:12.4924371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mHost=android.support.v4.app.FragmentActivity$HostCallbacks#63bb372
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mContainer=android.support.v4.app.FragmentActivity$HostCallbacks#63bb372
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:mCurState=5mStateSaved=falsemDestroyed=false
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:ViewHierarchy:
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:com.android.internal.policy.PhoneWindow$DecorView{e6f4440V.E........0,0-1080,1920}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.widget.LinearLayout{5abbf79V.E........0,0-1080,1794}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.view.ViewStub{f0d94beG.E........0,0-0,0#10203a9android:id/action_mode_bar_stub}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.widget.FrameLayout{50e691fV.E........0,0-1080,1794}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.FitWindowsLinearLayout{824646cV.E........0,0-1080,1794#7f0c0059app:id/action_bar_root}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.ViewStubCompat{59fda35G.E........0,0-0,0#7f0c005aapp:id/action_mode_bar_stub}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.ContentFrameLayout{38a3ecaV.E........0,0-1080,1794#1020002android:id/content}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v4.widget.DrawerLayout{b3a783bVFED....F..0,0-1080,1794#7f0c006dapp:id/drawer_layout}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.design.widget.CoordinatorLayout{1295b58V.ED.......0,0-1080,1794}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.design.widget.AppBarLayout{7c6f7baV.E........0,63-1080,210}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.Toolbar{680e4b1V.E........0,0-1080,147#7f0c006fapp:id/toolbar}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.AppCompatTextView{c757d96V.ED.......189,38-596,109}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.AppCompatImageButton{24e5d17VFED..C....0,0-147,147}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.ActionMenuView{284d504V.E........975,0-1080,147}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.ActionMenuPresenter$OverflowMenuButton{8e1aedVFED..C....0,10-105,136}
12-1012:16:12.4934371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.widget.RelativeLayout{30e566bV.E........0,210-1080,1794#7f0c0070app:id/include}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.design.widget.NavigationView{903dd22I.E........-735,0-0,1794#7f0c006eapp:id/nav_view}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.design.internal.NavigationMenuView{e51b3b3VFED.V.....0,0-735,1794#7f0c0077app:id/design_navigation_view}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.widget.LinearLayout{cfc3d70V.E........0,0-735,441#7f0c0076app:id/navigation_header_container}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.widget.LinearLayout{6be78e9V.E........0,0-735,420}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.AppCompatImageView{526a96eV.ED.......42,66-168,234#7f0c0084app:id/imageView}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.AppCompatTextView{229d80fV.ED.......42,234-693,327}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.support.v7.widget.AppCompatTextView{63fc09cV.ED.......42,327-519,378#7f0c0085app:id/textView}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/FragmentManager:android.view.View{a7cbaa5V.ED.......0,1794-1080,1920#1020030android:id/navigationBarBackground}
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlD/AndroidRuntime:ShuttingdownVM
12-1012:16:12.4944371-4371/de.thejakekols.brunoflo.teamgennewsqlE/AndroidRuntime:FATALEXCEPTION:main
Process:de.thejakekols.brunoflo.teamgennewsql,PID:4371
java.lang.IllegalArgumentException:Noviewfoundforid0x7f0c0071(de.thejakekols.brunoflo.teamgennewsql:id/content_main)forfragmentAddClass{560ed4#0id=0x7f0c0071}
atandroid.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1102)
atandroid.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
atandroid.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
atandroid.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
atandroid.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
atandroid.os.Handler.handleCallback(Handler.java:739)
atandroid.os.Handler.dispatchMessage(Handler.java:95)
atandroid.os.Looper.loop(Looper.java:148)
atandroid.app.ActivityThread.main(ActivityThread.java:5417)
atjava.lang.reflect.Method.invoke(NativeMethod)
atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
12-1012:16:12.4941555-1962/system_processW/ActivityManager:Forcefinishingactivityde.thejakekols.brunoflo.teamgennewsql/.MainActivity
12-1012:16:12.4981214-1616/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x333implycreationofhostcolorbuffer
[12-1012:16:12.5011555:1962D/]
HostConnection::get()NewHostConnectionestablished0x7fc54b5b7360,tid1962
12-1012:16:12.5111255-1621/?D/AudioFlinger:mixer(0xf44c0000)throttleend:throttletime(55)
12-1012:16:12.5131214-1214/?E/EGL_emulation:tid1214:eglCreateSyncKHR(1660):error0x3004(EGL_BAD_ATTRIBUTE)
12-1012:16:12.5771555-1962/system_processD/gralloc_ranchu:gralloc_unregister_buffer:exitingHostConnection(isbuffer-handlingthread)
12-1012:16:12.6711555-1606/system_processI/OpenGLRenderer:InitializedEGL,version1.4
12-1012:16:12.6881214-1617/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x900implycreationofhostcolorbuffer
12-1012:16:12.6941555-1606/system_processE/EGL_emulation:tid1606:eglSurfaceAttrib(1165):error0x3009(EGL_BAD_MATCH)
12-1012:16:12.6941555-1606/system_processW/OpenGLRenderer:FailedtosetEGL_SWAP_BEHAVIORonsurface0x7fc54b53fac0,error=EGL_BAD_MATCH
12-1012:16:12.6961214-1329/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x900implycreationofhostcolorbuffer
12-1012:16:12.6981214-1329/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x900implycreationofhostcolorbuffer
12-1012:16:13.0841555-1569/system_processW/ActivityManager:ActivitypausetimeoutforActivityRecord{32c16b2u0de.thejakekols.brunoflo.teamgennewsql/.MainActivityt338f}
12-1012:16:13.1171214-1579/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x900implycreationofhostcolorbuffer
12-1012:16:13.1251950-2080/com.android.launcher3E/EGL_emulation:tid2080:eglSurfaceAttrib(1165):error0x3009(EGL_BAD_MATCH)
12-1012:16:13.1251950-2080/com.android.launcher3W/OpenGLRenderer:FailedtosetEGL_SWAP_BEHAVIORonsurface0x7fc5574928c0,error=EGL_BAD_MATCH
12-1012:16:13.1261214-1329/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x900implycreationofhostcolorbuffer
12-1012:16:13.1311214-1329/?D/gralloc_ranchu:gralloc_alloc:format1andusage0x900implycreationofhostcolorbuffer
12-1012:16:13.6661950-2080/com.android.launcher3W/OpenGLRenderer:IncorrectlycalledbuildLayeronView:ShortcutAndWidgetContainer,destroyinglayer...
12-1012:16:13.6661950-2080/com.android.launcher3W/OpenGLRenderer:IncorrectlycalledbuildLayeronView:ShortcutAndWidgetContainer,destroyinglayer...
12-1012:16:14.8624371-4371/de.thejakekols.brunoflo.teamgennewsqlI/Process:Sendingsignal.PID:4371SIG:9
12-1012:16:14.8781555-1606/system_processE/Surface:getSlotFromBufferLocked:unknownbuffer:0x7fc548597ce0
12-1012:16:14.8871555-1708/system_processE/JavaBinder:!!!FAILEDBINDERTRANSACTION!!!(parcelsize=104)
12-1012:16:14.8871555-1708/system_processW/InputMethodManagerService:GotRemoteExceptionsendingsetActive(false)notificationtopid4371uid10041
12-1012:16:14.8891555-1708/system_processE/JavaBinder:!!!FAILEDBINDERTRANSACTION!!!(parcelsize=104)
12-1012:16:14.9081255-1621/?D/AudioFlinger:mixer(0xf44c0000)throttleend:throttletime(11)
12-1012:16:14.9221555-1625/system_processD/GraphicsStats:Buffercount:3
12-1012:16:14.9221555-1917/system_processI/WindowState:WINDEATH:Window{7880644u0de.thejakekols.brunoflo.teamgennewsql/de.thejakekols.brunoflo.teamgennewsql.MainActivity}
12-1012:16:14.9221555-1917/system_processW/WindowManager:Force-removingchildwinWindow{662c9bau0PopupWindow:81e55c2}fromcontainerWindow{7880644u0de.thejakekols.brunoflo.teamgennewsql/de.thejakekols.brunoflo.teamgennewsql.MainActivity}
12-1012:16:14.9261555-1625/system_processW/WindowManager:Failedlookingupwindow
java.lang.IllegalArgumentException:Requestedwindowandroid.os.BinderProxy#408fae5doesnotexist
atcom.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8733)
atcom.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8724)
atcom.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1209)
atandroid.os.BinderProxy.sendDeathNotice(Binder.java:558)
12-1012:16:14.9261555-1625/system_processI/WindowState:WINDEATH:null
I'm new into Android :)
The ID specified on an <include> tag overrides the ID of the root View in the inflated layout. This means that the RelativeLayout you're using to hold your Fragment's View does not have ID content_main after inflation. It has ID include, so the FragmentManager can't find the ViewGroup for the ID specified in the FragmentTransaction.
You can see this in your hierarchy listing:
android.widget.RelativeLayout{30e566b V.E..... ... 0,210-1080,1794 #7f0c0070 app:id/include}
Simply remove android:id="#+id/include" from the <include> tag in the app_bar_main layout.
I thing you have done mistake in the code
final View view = inflater.inflate(R.layout.fragment_add_user, container, false);
Please check the inflated layout is correct.

Categories

Resources