Fragmenty android- trywialny blad, ktorego nie widze

0

Czesc, ucze sie fragmentów w androidzie. I pierwszy banalna rzecz i juz nie widze,gdzie mam blad. Oto moj kod
Plik java z fragmentem

package com.example.lukasz.fragmenty;


import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class MainActivityFragment extends Fragment {

    public MainActivityFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View fragmentView = inflater.inflate(R.layout.fragment_main, container, false);

        return fragmentView;
    }
}

Plik java z glowna aktywnoscia

package com.example.lukasz.fragmenty;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

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

        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

        MainActivityFragment fragment = new MainActivityFragment();
        fragmentTransaction.add(R.id.fragmentLayout, fragment);
        fragmentTransaction.commit();
    }


    @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);
    }
}

Layout dla fragmentu

<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:background="#FFF"
    tools:context=".MainActivityFragment">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_fragment"></TextView>

</RelativeLayout>

i layout dla glownej aktywnosci

<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="horizontal"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="@string/main_word"
        ></TextView>

    <LinearLayout
        android:id="@+id/fragmentLayout"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal">

    </LinearLayout>
</LinearLayout>

no i jeszcze moj plik string.xml

<resources>
    <string name="app_name">Fragmenty</string>
    <string name="main_word">Główna aktywność!!!</string>
    <string name="hello_fragment">Witaj framgencie!</string>
    <string name="action_settings">Settings</string>
</resources>

I teraz czemu w glownej aktywnosci, gdzie w layout mam textView i tam ustawiam text  main_word to ten napis mi sie nie wyswietla jak to odpale w emulatorze?

Zapewne blad jest jakis  banalny, ale za cholere nie moge tego znalezc, dodawalem atrybuty i texColor i textSize w tym textView ale to nic nie pomagalo.

Z gory dzieki za wszelkie sugestie

0

Podany tutaj kod na pewno nie różni się od tego który buildowałeś?

0

o ile ctr c i ctr v dziala zgodnie z zaleceniami to sie nie rozni :)

0

Jedyne co mi przychodzi na myśl to różnica w zaimportowanych paczkach.
W MainActivity operujesz na

import android.support.v4.app.Fragment;

zaś sam fragment jest

import android.app.Fragment;

Potem może się opluć o fragmentManager'a ale to też sobie wyrównasz.

1 użytkowników online, w tym zalogowanych: 0, gości: 1