可能你没有得到我的问题。我在主页面上制作了可扩展的滑动菜单..现在,当我从可扩展的滑动菜单打开一个活动时,它将工作..但是从那个打开的活动我无法滑动我在主页面上的可扩展列表视图。我希望它就像一个Facebook或一个Gmail,但有可扩展的列表..我有章节,在每一章我有不同的主题,所以如果我打开可扩展列表中的章节,那么我不能直接从我的可扩展列表滑动章节,为此,我必须再次滑回去。 这是我的代码....``
我的新适配器
package com.example.drawerlayouttest;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
@SuppressWarnings("unchecked")
public class NewAdapter extends BaseExpandableListAdapter {
public ArrayList<String> groupItem, tempChild;
public ArrayList<Object> Childtem = new ArrayList<Object>();
public LayoutInflater minflater;
public Activity activity;
private final Context context;
public NewAdapter(Context context,ArrayList<String> grList, ArrayList<Object> childItem) {
this.context = context;
groupItem = grList;
this.Childtem = childItem;
}
public void setInflater(LayoutInflater mInflater, Activity act) {
this.minflater = mInflater;
activity = act;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
tempChild = (ArrayList<String>) Childtem.get(groupPosition);
TextView text = null;
if (convertView == null) {
convertView = new TextView(context);
}
text = (TextView) convertView;
text.setText(tempChild.get(childPosition));
text.setPadding(140, 20, 20, 20);
text.setTextSize(16);
// convertView.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// Toast.makeText(activity, tempChild.get(childPosition),
// Toast.LENGTH_SHORT).show();
// }
// });
convertView.setTag(tempChild.get(childPosition));
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return ((ArrayList<String>) Childtem.get(groupPosition)).size();
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public int getGroupCount() {
return groupItem.size();
}
@Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
@Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
tempChild = (ArrayList<String>) Childtem.get(groupPosition);
TextView text = null;
if (convertView == null) {
convertView = new TextView(context);
}
text = (TextView) convertView;
text.setText(tempChild.get(groupPosition));
text.setPadding(100, 20, 20, 40);
text.setTextSize(20);
// convertView.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// Toast.makeText(activity, tempChild.get(childPosition),
// Toast.LENGTH_SHORT).show();
// }
// });
convertView.setTag(tempChild.get(groupPosition));
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
(主要活动)
package com.example.drawerlayouttest;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
public class DrawerLayoutTest extends Activity implements OnChildClickListener {
private DrawerLayout drawer;
private ExpandableListView drawerList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer_layout_test);
setGroupData();
setChildGroupData();
initDrawer();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.drawer_layout_test, menu);
return true;
}
private void initDrawer() {
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerList = (ExpandableListView) findViewById(R.id.left_drawer);
drawerList.setAdapter(new NewAdapter(this, groupItem, childItem));
drawerList.setOnChildClickListener(this);
}
public void setGroupData() {
groupItem.add("TechNology");
groupItem.add("Mobile");
groupItem.add("Manufacturer");
groupItem.add("Extras");
}
ArrayList<String> groupItem = new ArrayList<String>();
ArrayList<Object> childItem = new ArrayList<Object>();
public void setChildGroupData() {
/**
* Add Data For TecthNology
*/
ArrayList<String> child = new ArrayList<String>();
child.add("Java");
child.add("Drupal");
child.add(".Net Framework");
child.add("PHP");
childItem.add(child);
/**
* Add Data For Mobile
*/
child = new ArrayList<String>();
child.add("Android");
child.add("Window Mobile");
child.add("iPHone");
child.add("Blackberry");
childItem.add(child);
/**
* Add Data For Manufacture
*/
child = new ArrayList<String>();
child.add("HTC");
child.add("Apple");
child.add("Samsung");
child.add("Nokia");
childItem.add(child);
/**
* Add Data For Extras
*/
child = new ArrayList<String>();
child.add("Contact Us");
child.add("About Us");
child.add("Location");
child.add("Root Cause");
childItem.add(child);
}
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
switch (groupPosition){
case 0:
switch (childPosition){
case 0:
Intent Intent = new Intent(this,Java.class);
startActivity(Intent);
break;
case 1:
Intent Intent1=new Intent(this,Apple.class);
startActivity(Intent1);
break;
case 2:
Intent Intent2=new Intent(this,Java.class);
startActivity(Intent2);
break;
case 3:
Intent Intent3=new Intent(this,Apple.class);
startActivity(Intent3);
break;
}
case 1:
switch (childPosition){
case 1:
Intent Intent1=new Intent(this,Apple.class);
startActivity(Intent1);
break;
case 2:
Intent Intent2=new Intent(this,Java.class);
startActivity(Intent2);
break;
case 3:
Intent Intent3=new Intent(this,Apple.class);
startActivity(Intent3);
break;
}
return false;
}
return false;
}
}
(我的XML文件)
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ExpandableListView
android:id="@+id/left_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:layout_gravity="start"
android:background="#6B8E23"
android:divider="#272727"
android:dividerHeight="0.5dp" />
</android.support.v4.widget.DrawerLayout>