Android 单击导航抽屉“普通”和“可扩展”列表视图时,布局变得无响应

Android 单击导航抽屉“普通”和“可扩展”列表视图时,布局变得无响应,android,listview,navigation-drawer,Android,Listview,Navigation Drawer,这是我的主要活动文件,其中包含抽屉布局 public abstract class ParentActivity extends AppCompatActivity implements NetworkStateReceiverListener { private final String TAG = ParentActivity.this.getClass().getSimpleName(); protected ListView mDrawerList; pro

这是我的主要活动文件,其中包含抽屉布局

public abstract class ParentActivity extends AppCompatActivity implements NetworkStateReceiverListener {
    private final String TAG = ParentActivity.this.getClass().getSimpleName();

    protected ListView mDrawerList;


    protected static int position;

    private static boolean isLaunch = true;


    private DrawerLayout mDrawerLayout;



    private ActionBarDrawerToggle actionBarDrawerToggle;
    private boolean mSlideState;
    private MenuItem drawer_btn;
    private RelativeLayout subItem1;
    private RelativeLayout subItem2;
    private RelativeLayout subItem3;
    public NetworkStateReceiver networkStateReceiver = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.navigation_drawer_base_layout);
        Utils.registerNetworkStateReceiver(this, networkStateReceiver, this);
        frameLayout = (FrameLayout) findViewById(R.id.content_frame);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);
        drawer_btn = (MenuItem) findViewById(R.id.navigation_drawer_button);
        NavigationAdapter adapter = new NavigationAdapter(this);





        mDrawerList.setAdapter(adapter);
        mDrawerList.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                openActivity(position);
            }
        });

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        getSupportActionBar().setLogo(R.drawable.logo);
        getSupportActionBar().setDisplayUseLogoEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
        mDrawerLayout.setFocusableInTouchMode(false);

        actionBarDrawerToggle = new ActionBarDrawerToggle(
                this,                       
                mDrawerLayout,              
                R.drawable.ic_launcher,     
                R.string.open_drawer,     
                R.string.close_drawer)    
            @Override
            public void onDrawerClosed(View drawerView) {

                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                super.onDrawerClosed(drawerView);
                mSlideState = false;
            }

            @Override
            public void onDrawerOpened(View drawerView) {

                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                mSlideState = true;
                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(actionBarDrawerToggle);



        if (isLaunch) {

            isLaunch = false;
            openActivity(0);
        }
    }


    protected void openActivity(int position) {


        mDrawerLayout.closeDrawer(mDrawerList);
        ParentActivity.position = position; //Setting currently selected position in this field so that it will be available in our child activities.

        switch (position) {
            case 0:

                break;
            case 1: {
                Intent intent = new Intent(this, HotelListScreen.class);
                Utils.startActivityClearTop(this, intent);
            }
            break;

            case 2: {
                Intent intent = new Intent(this, CallUsScreen.class);
                Utils.startActivityClearTop(this, intent);
            }
            break;
            case 3:

                break;
            case 4:

                break;
            case 5:

                break;
            case 6:

                break;
            case 8: {
                if (ApplicationDataLayer.getInstance().getSelectedHotel() != null) {
                    Intent intent = new Intent(this, BankDetails.class);
                    Utils.startActivityClearTop(this, intent);
                } else {
                    dialog = MultipleDialogs.createDialogOneBtnWithoutTitle(this, this.getResources().getString(R.string.pls_select_hotel), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                }

            }
            break;
            default:
                break;
        }
        Toast.makeText(this, "Selected Item Position::" + position, Toast.LENGTH_LONG).show();


    }

    private Dialog dialog;

    private ActionBar actionBar = null;

    public void setUpActionBar() {
        actionBar = getSupportActionBar();
        actionBar.show();
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_bg));

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        if (item.getItemId() == android.R.id.home) {
            onBackPressed();
            return true;
        }
        if (item.getItemId() == R.id.navigation_drawer_button) {
            if (mSlideState) {
                mDrawerLayout.closeDrawer(mDrawerList);
            } else
                mDrawerLayout.openDrawer(mDrawerList);
        }
        return false;

    }


    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
        boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);

        return super.onPrepareOptionsMenu(menu);
    }


    @Override
    public void onBackPressed() {
        if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
            mDrawerLayout.closeDrawer(mDrawerList);
        }
        super.onBackPressed();
    }


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


    @Override
    protected void onDestroy() {
        if (null != networkStateReceiver && null != this) {
            Utils.removeNetworkStateReceiverListener(this, networkStateReceiver, this);
        }
        super.onDestroy();
    }
公共抽象类ParentActivity扩展AppCompatActivity实现NetworkStateReceiveListener{
private final String TAG=ParentActivity.this.getClass().getSimpleName();
受保护的ListView mDrawerList;
保护静态int位置;
私有静态布尔值isLaunch=true;
私人抽屉布局mDrawerLayout;
私人动作bardrawertoggle动作bardrawertoggle;
私有布尔状态;
私人菜单出票人;
私人关系子项1;
私人关系子项2;
私人关系子项3;
公共网络StateReceiver NetworkStateReceiver=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、导航、抽屉、基础布局);
registerNetworkStateReceiver(this,networkStateReceiver,this);
frameLayout=(frameLayout)findviewbyd(R.id.content\u frame);
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
mDrawerList=(ListView)findViewById(R.id.left\u抽屉);
抽屉\u btn=(菜单项)findViewById(R.id.navigation\u抽屉\u按钮);
NavigationAdapter=新的NavigationAdapter(此);
mDrawerList.setAdapter(适配器);
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
开放活动(职位);
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setLogo(R.drawable.logo);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
mDrawerLayout.setFocusableInTouchMode(false);
actionBarDrawerToggle=新actionBarDrawerToggle(
这
mDrawerLayout,
R.drawable.ic_发射器,
R.string.打开抽屉,
右弦关闭(抽屉)
@凌驾
图纸上的公共空白已关闭(视图抽屉视图){
InvalidateOptions SMenu();//创建对OnPrepareOptions SMenu()的调用
super.onDrawerClosed(抽屉视图);
mSlideState=false;
}
@凌驾
打开图纸上的公共空白(视图抽屉视图){
InvalidateOptions SMenu();//创建对OnPrepareOptions SMenu()的调用
mSlideState=true;
super.onDrawerOpened(抽屉视图);
}
@凌驾
绘图滑块上的公共空白(视图抽屉视图、浮动滑块偏移){
super.onDrawerSlide(抽屉视图、滑块偏移);
}
@凌驾
DrawerStateChanged上的公共无效(int newState){
super.onDrawerStateChanged(newState);
}
};
mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
如果(isLaunch){
isLaunch=false;
openActivity(0);
}
}
受保护的void openActivity(int位置){
mDrawerLayout.closeDrawer(mDrawerList);
ParentActivity.position=position;//在此字段中设置当前选定的位置,以便在子活动中可用。
开关(位置){
案例0:
打破
案例1:{
Intent Intent=新Intent(这是HotelListScreen.class);
Utils.startActivityClearTop(本,意向);
}
打破
案例2:{
Intent Intent=新的Intent(这是CallUsScreen.class);
Utils.startActivityClearTop(本,意向);
}
打破
案例3:
打破
案例4:
打破
案例5:
打破
案例6:
打破
案例8:{
if(ApplicationDataLayer.getInstance().getSelectedHotel()!=null){
意向意向=新意向(此为BankDetails.class);
Utils.startActivityClearTop(本,意向);
}否则{
dialog=MultipleDialogs.createdialogonebtnwhithouttitle(this,this.getResources().getString(R.string.pls\u select\u hotel),new View.OnClickListener(){
@凌驾
公共void onClick(视图v){
dialog.dismise();
}
});
dialog.show();
}
}
打破
违约:
打破
}
Toast.makeText(此“所选项目位置::”+位置,Toast.LENGTH_LONG).show();
}
私人对话;
私有ActionBar ActionBar=null;
公共void setUpActionBar(){
actionBar=getSupportActionBar();
actionBar.show();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_bg));
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
if(item.getItemId()==android.R.id.home){
onBackPressed();
返回true;
}
if(item.getItemId()==R.id.navigation\u抽屉\u按钮){
如果(MSL状态){
mDrawerLayout.closeDrawer(mDrawerList);
}否则
mDrawerLayout.openDrawer(mDrawerList);
}
返回false;
}
@凌驾
公共布尔值OnPrepareOptions菜单(菜单){
//如果导航抽屉打开,则隐藏与内容视图相关的操作项
喝倒采
public class NavigationAdapter extends BaseAdapter {
private Activity mActivity;
private ArrayList<DrawerHolderPOJO> mDrawerOptions = new ArrayList<DrawerHolderPOJO>();
private ImageView arrow;
private RelativeLayout subItem1;
private RelativeLayout subItem2;
private RelativeLayout subItem3;
private boolean isHelpOpen = false;

public NavigationAdapter(Activity activity) {
    this.mActivity = activity;

    String[] title = activity.getResources().getStringArray(R.array.drawer_options_string);
    String[] subTitleHelp = activity.getResources().getStringArray(R.array.drawer_options_help_string);

    TypedArray ar = activity.getResources().obtainTypedArray(R.array.drawer_options_img);
    int len = ar.length();
    int[] image = new int[len];
    for (int i = 0; i < len; i++) {
        image[i] = ar.getResourceId(i, 0);
    }
    ar.recycle();

    int noSubcontentLayout = 0;
    boolean subcontentPresent = false;
    mDrawerOptions.add(new DrawerHolderPOJO(title[0], noSubcontentLayout, image[0], subcontentPresent));
    mDrawerOptions.add(new DrawerHolderPOJO(title[1], noSubcontentLayout, image[1], subcontentPresent));
    if (!(activity instanceof HotelListScreen || activity instanceof HotelDetailScreen)) {
        mDrawerOptions.add(new DrawerHolderPOJO(title[2], noSubcontentLayout, image[2], subcontentPresent));
        mDrawerOptions.add(new DrawerHolderPOJO(title[3], noSubcontentLayout, image[3], subcontentPresent));
        mDrawerOptions.add(new DrawerHolderPOJO(title[4], noSubcontentLayout, image[4], subcontentPresent));
        mDrawerOptions.add(new DrawerHolderPOJO(title[5], noSubcontentLayout, image[5], subcontentPresent));
        mDrawerOptions.add(new DrawerHolderPOJO(title[6], noSubcontentLayout, image[6], subcontentPresent));
        mDrawerOptions.add(new DrawerHolderPOJO(title[7], noSubcontentLayout, image[7], subcontentPresent));
        mDrawerOptions.add(new DrawerHolderPOJO(title[8], noSubcontentLayout, image[8], subcontentPresent));
    }
    mDrawerOptions.add(new DrawerHolderPOJO(title[9], noSubcontentLayout, image[9], subcontentPresent));

    //HELP TODO Need to give noSubcontentLayout
    mDrawerOptions.add(new DrawerHolderPOJO(title[10], R.layout.drawer_list_sub_item, image[10], true));
    mDrawerOptions.add(new DrawerHolderPOJO(title[11], noSubcontentLayout, image[11], subcontentPresent));
    mDrawerOptions.add(new DrawerHolderPOJO(title[12], noSubcontentLayout, image[12], subcontentPresent));


}


private class ViewHolder {
    TextView optionName;
    ImageView imageOption;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    LayoutInflater mInflater = (LayoutInflater)
            mActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.drawer_list_item, null);
        holder = new ViewHolder();

        holder.optionName = (TextView) convertView.findViewById(R.id.option_name);
        holder.imageOption = (ImageView) convertView.findViewById(R.id.option_img);
        arrow = (ImageView) convertView.findViewById(R.id.arrow);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }


    DrawerHolderPOJO rowItem = (DrawerHolderPOJO) getItem(position);

    holder.optionName.setText(rowItem.getItemName());
    holder.imageOption.setImageResource(rowItem.getItemImage());

    if (rowItem.isSubcontent()) {
        arrow.setVisibility(View.VISIBLE);
        arrow.setTag(convertView);
        arrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View cView = (View) v.getTag();
                subItem1 = (RelativeLayout) cView.findViewById(R.id.sub_item1);
                subItem2 = (RelativeLayout) cView.findViewById(R.id.sub_item2);
                subItem3 = (RelativeLayout) cView.findViewById(R.id.sub_item3);
                arrow = (ImageView) cView.findViewById(R.id.arrow);
                TextView subText1 = (TextView) subItem1.findViewById(R.id.option_name);
                TextView subText2 = (TextView) subItem2.findViewById(R.id.option_name);
                TextView subText3 = (TextView) subItem3.findViewById(R.id.option_name);
                if (!isHelpOpen) {
                    isHelpOpen = true;

                    arrow.setImageResource(R.drawable.up_arrow_white);


                    subText1.setText("Tutorial Video");
                    subText2.setText("FAQs");
                    subText3.setText("Feedback");
                    subItem1.setVisibility(View.VISIBLE);
                    subItem2.setVisibility(View.VISIBLE);
                    subItem3.setVisibility(View.VISIBLE);
                } else {
                    isHelpOpen = false;
                    arrow.setImageResource(R.drawable.down_arrow_white);
                    subItem1.setVisibility(View.GONE);
                    subItem2.setVisibility(View.GONE);
                    subItem3.setVisibility(View.GONE);
                }
            }
        });


    }
    return convertView;
}

@Override
public int getCount() {
    return mDrawerOptions.size();
}

@Override
public Object getItem(int position) {
    return mDrawerOptions.get(position);
}

@Override
public long getItemId(int position) {
    return mDrawerOptions.indexOf(getItem(position));
}
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:id="@+id/list_item"
     android:orientation="vertical">
    <RelativeLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:gravity="center"
     android:orientation="vertical"
     android:padding="@dimen/hotel_detail_item_padding"
       >
    <ImageView
      android:id="@+id/option_img"
      android:layout_width="39dp"
      android:layout_height="39dp"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true"
      android:layout_centerInParent="true"
      android:layout_marginTop="@dimen/hotel_detail_item_margin_top_bottom"
    android:layout_marginBottom="@dimen/hotel_detail_item_margin_top_bottom"
    android:layout_marginRight="@dimen/hotel_detail_item_margin_left_right"/>
<ImageView
    android:id="@+id/arrow"
    android:layout_width="39dp"
    android:layout_height="39dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_centerInParent="true"
    android:layout_gravity="right"
    android:src="@drawable/down_arrow_white"
android:layout_marginLeft="@dimen/hotel_detail_image_item_margin_left_right"
    android:visibility="gone"/>
<TextView
    android:id="@+id/option_name"
    style="@style/TextFontStyleNavigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_toLeftOf="@id/arrow"
    android:layout_toRightOf="@id/option_img"
    android:text="Large Text"
    android:singleLine="true"/>
  </RelativeLayout>
      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
       android:background="#b3b3b3">
      <include
      android:id="@+id/sub_item1"
      layout="@layout/drawer_list_sub_item"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      />
     <include
      android:id="@+id/sub_item2"
      layout="@layout/drawer_list_sub_item"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      />
     <include
      android:id="@+id/sub_item3"
      layout="@layout/drawer_list_sub_item"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      />
    </LinearLayout>
   </LinearLayout>
    <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="@dimen/hotel_detail_item_padding"
android:visibility="gone">


<TextView
    android:id="@+id/option_name"
    style="@style/TextFontStyleNavigationSubItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:paddingLeft="@dimen/padding_left_drawer_sub_item"
    android:singleLine="true"
    android:text="Large Text" />