Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 导航抽屉打开空白活动_Android_Android Fragments_Android Activity_Navigation Drawer - Fatal编程技术网

Android 导航抽屉打开空白活动

Android 导航抽屉打开空白活动,android,android-fragments,android-activity,navigation-drawer,Android,Android Fragments,Android Activity,Navigation Drawer,我正在开发一个使用导航抽屉的应用程序。我通过点击按钮呼叫导航抽屉。但问题是,当我按下按钮时,我得到的是空白页,我的第一个项目并没有被选为主要项目,甚至我把它指示为主要项目 这是我的代码,这是我的主要活动: package sightsOfAlmaty; import sightsOfAlmaty.NavDrawerListAdapter; import sightsOfAlmaty.NavDrawerItem; import java.util.ArrayList; import

我正在开发一个使用导航抽屉的应用程序。我通过点击按钮呼叫导航抽屉。但问题是,当我按下按钮时,我得到的是空白页,我的第一个项目并没有被选为主要项目,甚至我把它指示为主要项目

这是我的代码,这是我的主要活动:

    package sightsOfAlmaty;

import sightsOfAlmaty.NavDrawerListAdapter;
import sightsOfAlmaty.NavDrawerItem;

import java.util.ArrayList;

import com.example.new1.R;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.app.FragmentManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;

public class sightsOfAlmaty extends ActionBarActivity {
private DrawerLayout mDrawerLayout;
protected ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private static boolean isLaunch = true;

// nav drawer title
private CharSequence mDrawerTitle;

// used to store app title
protected CharSequence mTitle;

// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;

private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
protected FrameLayout frameLayout;

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

    mTitle = mDrawerTitle = getTitle();

    // load slide menu items
    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

    // nav drawer icons from resources
    navMenuIcons = getResources()
            .obtainTypedArray(R.array.nav_drawer_icons);
    frameLayout = (FrameLayout)findViewById(R.id.frame_container);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

    navDrawerItems = new ArrayList<NavDrawerItem>();

    // adding nav drawer items to array
    // Home
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
    // Find People
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
    // Photos
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
    // Communities, Will add a counter here
    //navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
    // Pages
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
    // What's hot, We  will add a counter here
//  navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));


    // Recycle the typed array
    navMenuIcons.recycle();
    // setting the nav drawer list adapter
            adapter = new NavDrawerListAdapter(getApplicationContext(),
                    navDrawerItems);

            mDrawerList.setAdapter(adapter);
            mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

            // enabling action bar app icon and behaving it as toggle button
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            //R.drawable.ic_drawer, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
            super.onDrawerClosed(view);

        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
            super.onDrawerOpened(drawerView);

        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
        }

        @Override
        public void onDrawerStateChanged(int newState) {
            super.onDrawerStateChanged(newState);
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    /**
     * As we are calling BaseActivity from manifest file and this base activity is intended just to add navigation drawer in our app.
     * We have to open some activity with layout on launch. So we are checking if this BaseActivity is called first time then we are opening our first activity.
     * */
    if(isLaunch){
         /**
          *Setting this flag false so that next time it will not open our first activity.
          *We have to use this flag because we are using this BaseActivity as parent activity to our other activity. 
          *In this case this base activity will always be call when any child activity will launch.
          */
        isLaunch = false;
        displayView(0);
    }
   }

   /**
     * Slide menu item click listener
    * */
    private class SlideMenuClickListener implements
        ListView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        // display view for selected nav drawer item
        displayView(position);
      }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // toggle nav drawer on selecting action bar app icon/title
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // Handle action bar actions click
    switch (item.getItemId()) {
    case R.id.action_settings:
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
    }

   /* *
     * Called when invalidateOptionsMenu() is triggered
    */
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
    }

    /**
     * Diplaying fragment view for selected nav drawer list item
     * */
    private void displayView(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;

    Intent intent;
    switch (position) {
    case 0:
        /*intent = new Intent(this, HomeFragment.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        this.startActivity(intent);*/
        startActivity(new Intent(this, HomeFragment.class));
        return;
    case 1:
        //fragment = new FindPeopleFragment();
        break;
    /*case 2:
        fragment = new PhotosFragment();
        break;
    case 3:
        fragment = new CommunityFragment();
        break;
    case 4:
        fragment = new PagesFragment();
        break;
    case 5:
        fragment = new WhatsHotFragment();
        break;
    */
    default:
        break;
    }

    /*if (fragment != null) {
        android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();*/

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    //} else {
        // error in creating fragment
    //  Log.e("MainActivity", "Error in creating fragment");
    //}
    }

    @Override
    public void setTitle(CharSequence title) {
    mTitle = title;
    getSupportActionBar().setTitle(mTitle);
    }

   /**
    * When using the ActionBarDrawerToggle, you must call it during
    * onPostCreate() and onConfigurationChanged()...
    */

   @Override
    protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
    }

   @Override
    public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Pass any configuration change to the drawer toggls
    mDrawerToggle.onConfigurationChanged(newConfig);
    }

    }
包裹瞄准;
进口Almaty.navDrawerlistatadapter;
进口Almaty.NavDrawerItem;
导入java.util.ArrayList;
导入com.example.new1.R;
导入android.app.Activity;
导入android.support.v4.app.Fragment;
导入android.support.v4.app.FragmentActivity;
导入android.app.FragmentManager;
导入android.content.Intent;
导入android.content.res.Configuration;
导入android.content.res.TypedArray;
导入android.os.Bundle;
导入android.support.v7.app.ActionBarActivity;
导入android.support.v7.app.ActionBarDrawerToggle;
导入android.support.v4.widget.DrawerLayout;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.FrameLayout;
导入android.widget.ListView;
公共级目击恐怖袭击扩大了行动范围{
私人抽屉布局mDrawerLayout;
受保护的ListView mDrawerList;
私有操作bardrawertoggle mDrawerToggle;
私有静态布尔值isLaunch=true;
//导航抽屉标题
私有字符序列mDrawerTitle;
//用于存储应用程序标题
受保护的字符序列mTitle;
//幻灯片菜单项
私有字符串[]navMenuTitles;
专用型雷达导航仪;
私人ArrayList NavWrites;
专用导航适配器;
受保护的框架布局;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sights);
mTitle=mDrawerTitle=getTitle();
//加载幻灯片菜单项
navMenuTitles=getResources().getStringArray(R.array.nav\u抽屉\u项目);
//参考资料中的导航抽屉图标
navMenuIcons=getResources()
.obtainTypedArray(R.array.nav_drawer_图标);
frameLayout=(frameLayout)findviewbyd(R.id.frame\u容器);
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
mDrawerList=(ListView)findViewById(R.id.list\u slidermenu);
navDrawerItems=新的ArrayList();
//将导航抽屉项添加到阵列
//家
添加(新的NavDrawerItem(navMenuTitles[0],navMenuIcons.getResourceId(0,-1));
//找人
添加(新的NavDrawerItem(navMenuTitles[1],navMenuIcons.getResourceId(1,-1));
//照片
添加(新的NavDrawerItem(navMenuTitles[2],navMenuIcons.getResourceId(2,-1));
//社区,将在此处添加一个计数器
//添加(新的NavDrawerItem(navMenuTitles[3],navMenuIcons.getResourceId(3,-1),true,“22”);
//页数
add(新的NavDrawerItem(navMenuTitles[4],navMenuIcons.getResourceId(4,-1));
//什么是热的,我们将在这里加一个计数器
//add(新的NavDrawerItem(navMenuTitles[5],navMenuIcons.getResourceId(5,-1),true,“50+”));
//回收类型化数组
navMenuIcons.recycle();
//设置导航抽屉列表适配器
适配器=新的NavDroperListAdapter(getApplicationContext(),
纳维特姆斯);
mDrawerList.setAdapter(适配器);
setOnItemClickListener(新的SlideMenuClickListener());
//启用操作栏应用程序图标并将其作为切换按钮
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mDrawerToggle=新操作BarDrawerToggle(此,mDrawerLayout,
//R.drawable.ic_抽屉,//导航菜单切换图标
R.string.app_name,//导航抽屉打开-可访问性说明
R.string.app_name//nav抽屉关闭-可访问性说明
) {
公共无效onDrawerClosed(视图){
getSupportActionBar().setTitle(mTitle);
//调用onPrepareOptions菜单()以显示操作栏图标
无效操作菜单();
super.onDrawerClosed(视图);
}
打开图纸上的公共空白(视图抽屉视图){
getSupportActionBar().setTitle(mDrawerTitle);
//调用onPrepareOptions菜单()隐藏操作栏图标
无效操作菜单();
super.onDrawerOpened(抽屉视图);
}
@凌驾
绘图滑块上的公共空白(视图抽屉视图、浮动滑块偏移){
super.onDrawerSlide(抽屉视图、滑块偏移);
}
@凌驾
DrawerStateChanged上的公共无效(int newState){
super.onDrawerStateChanged(newState);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
/**
*因为我们正在从清单文件调用BaseActivity,这个基本活动只是为了在我们的应用程序中添加导航抽屉。
*我们必须在启动时打开一些布局为的活动。因此,我们正在检查此BaseActivity是否第一次调用,然后我们将打开第一个活动。
* */
如果(isLaunch){
/**
*将此标志设置为false,以便下次它不会打开我们的第一个活动。
*我们必须使用此标志,因为我们将此BaseActivity用作其他活动的父活动。
*在这种情况下,当任何子活动启动时,将始终调用此基本活动。
*/
isLaunch=false;
显示视图(0);
}
}
/**
*幻灯片菜单项单击“侦听器”
* */
私有类SlideMenuClickListener实现
ListView.com侦听器{
@凌驾
public void onItemClick(AdapterView父视图、视图、整型位置、,
长id){
//所选导航抽屉项目的显示视图
显示视图(位置);
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
getMenuInflater()。充气(R。
package sightsOfAlmaty;

import java.util.Hashtable;


import com.example.new1.GPSTracker;

import com.example.new1.R;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class HomeFragment extends sightsOfAlmaty {

public HomeFragment(){}

private GoogleMap map;
GPSTracker gps;

Marker marker;
private Hashtable<String, String> markers;
private ImageLoader imageLoader;
private DisplayImageOptions options;
protected static int position;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    mDrawerList.setItemChecked(position, true);
    setTitle(mTitle);
    getLayoutInflater().inflate(R.layout.fragment_home, frameLayout);
    /**
     * Setting title and itemChecked  

    */

    gps = new GPSTracker(this);

    LatLng myloc = new LatLng(gps.getLatitude(), gps.longitude);

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map2)).getMap();
    map.getUiSettings(  ).setZoomControlsEnabled(true); // true to enable
     map.moveCamera(CameraUpdateFactory.newLatLngZoom(myloc, 15));
     map.animateCamera(CameraUpdateFactory.zoomTo(13), 2000, null);



}
 }
    if(isLaunch){
     /**
      *Setting this flag false so that next time it will not open our first activity.
      *We have to use this flag because we are using this BaseActivity as parent activity to our other activity. 
      *In this case this base activity will always be call when any child activity will launch.
      */
    isLaunch = false;
    displayView(0);
}
    if(savedInstanceState == null) {
         displayView(0);
    }