我想將可擴展列表視圖中各個組項目的子項目顯示爲單獨的列表視圖。如何在其他列表視圖中顯示其各個組項目的子項目
我也做了以下
package com.example.demo_data1;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.Toast;
@SuppressLint("NewApi")
public class DrawerLayoutTest extends Activity implements OnChildClickListener {
private DrawerLayout drawer;
private ExpandableListView drawerList;
private ActionBarDrawerToggle actionBarDrawerToggle;
@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);
// actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer,
// R.drawable.ic_drawer, R.string.open_drawer,
// R.string.close_drawer) {
// public void onDrawerClosed(View view) {
// getActionBar().setSubtitle("open");
// }
//
// /** Called when a drawer has settled in a completely open state. */
// public void onDrawerOpened(View drawerView) {
// getActionBar().setSubtitle("close");
// }
//
// };
//
// drawer.setDrawerListener(actionBarDrawerToggle);
}
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);
}
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
switch (groupPosition)
{
case 0:
switch (childPosition)
{
case 0:
MainActivity();
break;
case 1:
//
}
}
return false;
}
private void MainActivity(){
Intent myIntent = new Intent(this, MainActivity.class);
startActivity(myIntent);
}
}
現在,這裏在上面的代碼中的子項越來越顯示在同一個列表視圖組項目下,而不是我想旁邊顯示組在不同的列表視圖中的子項項目列表視圖。
請幫我一下,堅持了很久。
任何有關這方面的幫助將不勝感激。
另一個列表視圖 – 2015-03-02 06:18:00
使用童工的ArrayList能不能幫我用邏輯或某些例子。 – 2015-03-02 06:18:51
你想要什麼?當你點擊你的gruop項目,然後打開新的活動,並有一個列表視圖? – 2015-03-02 06:21:24