2016-06-09 11 views
1

Ich habe versucht, ein einfaches contentFragment aufzublasen, nachdem ich auf den Tab in meiner Navigationsleiste geklickt habe. Hier ist meine CentralView Klasse, die den Versuch enthält das FragmentAndroid-Fragment, das nach der Transaktion nicht aufgebläht wird

import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.app.FragmentManager; 
import android.app.FragmentTransaction; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.os.AsyncTask; 
import android.support.design.widget.NavigationView; 
import android.support.v4.widget.DrawerLayout; 
import android.support.v7.app.ActionBarDrawerToggle; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.support.v7.widget.Toolbar; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.SubMenu; 
import android.view.View; 
import android.widget.Toast; 

@SuppressWarnings("deprecation") 
public class CentralView extends AppCompatActivity { 

    private Toolbar toolbar; 
    private NavigationView navigationView; 
    private DrawerLayout drawerLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_central_view); 

     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     navigationView = (NavigationView) findViewById(R.id.navigation_view); 
     navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { 
      @Override 
      public boolean onNavigationItemSelected(MenuItem menuItem) { 


       //Checking if the item is in checked state or not, if not make it in checked state 
       if(menuItem.isChecked()) menuItem.setChecked(false); 
       else menuItem.setChecked(true); 

       //Closing drawer on item click 
       drawerLayout.closeDrawers(); 

       //Check to see which item was being clicked and perform appropriate action 
       switch (menuItem.getItemId()){ 


        //Replacing the main content with ContentFragment Which is our Inbox View; 
        case R.id.home: 
         Toast.makeText(getApplicationContext(),"Inbox Selected",Toast.LENGTH_SHORT).show(); 
         ContentFragment fragment = new ContentFragment(); 
         android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 
         fragmentTransaction.replace(R.id.frame,fragment); 
         fragmentTransaction.commit(); 
         return true; 

Und hier ist meine ContentFragment Klasse

import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

/** 
* Created by Admin on 04-06-2015. 
*/ 
public class ContentFragment extends Fragment { 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View v = inflater.inflate(R.layout.fragment_content_fragment,container,false); 
     return v; 
    } 
} 

ich gesucht habe Stackoverflow aufzublasen und während die Menschen haben ähnliche Probleme hatten, keine der Korrekturen hat für mich gearbeitet. Entschuldigung, wenn es da draußen ist. Hier ist der XML-Code für mein Gehalt Fragment als auch

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="INBOX" 
     android:padding="8dp" 
     android:textColor="#fff" 
     android:background="@color/colorPrimary" 
     android:textSize="28sp" 
     android:id="@+id/textView" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

bearbeiten: Hinzufügen activity_central_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
             xmlns:tools="http://schemas.android.com/tools" 
             xmlns:app="http://schemas.android.com/apk/res-auto" 
             android:id="@+id/drawer" 
             android:layout_width="match_parent" 
             android:layout_height="match_parent" 
             android:fitsSystemWindows="true" 
             tools:context=".CentralView"> 

    <LinearLayout 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:orientation="vertical" 
     > 
     <include 
      android:id="@+id/toolbar" 
      layout="@layout/tool_bar"/> 
     <FrameLayout 
      android:id="@+id/frame" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

     </FrameLayout> 
    </LinearLayout> 
    <android.support.design.widget.NavigationView 
     android:id="@+id/navigation_view" 
     android:layout_height="match_parent" 
     android:layout_width="wrap_content" 
     android:layout_gravity="start" 
     app:headerLayout="@layout/header" 
     app:menu="@menu/drawer"/> 
</android.support.v4.widget.DrawerLayout> 
+0

Können Sie bitte 'activity_central_view.xml' zu Ihrer Frage hinzufügen? –

+0

@ cricket_007 hinzugefügt –

+0

Was haben Sie bisher zum Debuggen getan? Wurde der "Inbox Selected" -Toast angezeigt? Es gibt eine Menge Code, den Sie gepostet haben. Helfen Sie anderen, indem Sie das Problem eingrenzen. –

Antwort

2

Ich vermute, Ihr tool_bar Layout könnte eine Höhe von match_parent werden müssen.

Könnten Sie bitte tool_bar Datei freigeben?

+0

Sie hatten Recht! Meine Symbolleiste XML wurde abgehört und das Fragment war davon abhängig. War zurück gekommen, um meine Antwort zu aktualisieren, als ich deine sah. Sehr geschätzt. –