Помогите пожайлуста с отображением Фрагментов на Активити, не работает с этим кодом Taxi (fragment): '
public class Taxi extends Fragment {
Button uber_call;
Button uber_download;
Button uklon_download;
Button uklon_order_online;
Button taxi_plus_call;
Button taxi_plus_order_onlinecall;
Button taxi_plus_download;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uber_call = getView().findViewById(R.id.uber_call);
uber_download = getView().findViewById(R.id.uber_download);
uklon_download = getView().findViewById(R.id.uklon_download);
uklon_order_online = getView().findViewById(R.id.uklon_order_online);
taxi_plus_call = getView().findViewById(R.id.taxi_plus_call);
taxi_plus_order_onlinecall = getView().findViewById(R.id.taxi_plus_order_online);
taxi_plus_download = getView().findViewById(R.id.taxi_plus_download);
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.uber_call:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:9988")), "Call"));
break;
case R.id.uber_download:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.ubercab&hl=en")), "Browser"));
break;
case R.id.uklon_download:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=ua.com.uklontaxi&hl=en")), "Browser"));
break;
case R.id.uklon_order_online:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.uklon.com.ua/")), "Browser"));
break;
case R.id.taxi_plus_call:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:244")), "Call"));
break;
case R.id.taxi_plus_order_online:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse("http://taxiplus.ua/")), "Browser"));
break;
case R.id.taxi_plus_download:
startActivity(Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=sss.taxi.plus")), "Browser"));
break;
}
}
};
uber_call.setOnClickListener(onClickListener);
uber_download.setOnClickListener(onClickListener);
uklon_download.setOnClickListener(onClickListener);
uklon_order_online.setOnClickListener(onClickListener);
taxi_plus_call.setOnClickListener(onClickListener);
taxi_plus_order_onlinecall.setOnClickListener(onClickListener);
taxi_plus_download.setOnClickListener(onClickListener);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_taxi, null);
}
}'
Drawer: '
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
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 Drawer extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
Taxi taxi;
FragmentTransaction fragmentTransaction;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
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);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
taxi = new Taxi();
fragmentTransaction = getFragmentManager().beginTransaction();
if (id == R.id.nav_home) {
} else if (id == R.id.nav_bus) {
} else if (id == R.id.nav_funicular) {
} else if (id == R.id.nav_minibus) {
} else if (id == R.id.nav_subway) {
} else if (id == R.id.nav_city_train) {
} else if (id == R.id.nav_tram) {
} else if (id == R.id.nav_trolleybus) {
} else if (id == R.id.nav_taxi) {
/*Intent intent = new Intent(Drawer.this, Tax.class);
startActivity(intent);*/
fragmentTransaction.replace(R.id.main_frame_layout, taxi);
} else if (id == R.id.nav_hotels) {
} else if (id == R.id.nav_leisure) {
} else if (id == R.id.nav_need_to_know) {
} else if (id == R.id.nav_emergencies) {
Intent intent = new Intent(Drawer.this, Emergencies.class);
startActivity(intent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
'
fragmentTransaction.replace(R.id.main_frame_layout, taxi).commit();
)