如何使用可扩展列表的 xml 布局?
您好,我有这个可扩展列表,当我尝试使用此代码将其连接到 xml 文件时,出现错误。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directions);
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
使用此代码,当我单击重定向到整个 java 文件的按钮时,我会强制关闭。 (完整代码见下文) 日志猫是这样说的:
10-25 17:37:39.512: 错误/AndroidRuntime(547): java.lang.RuntimeException:无法启动活动 组件信息{com.sammy.umass/com.sammy.umass.DirectionsScreenActivity}: java.lang.RuntimeException:您的内容必须有一个 id属性为'android.R.id.list'的ExpandableListView
我只需要删除标题栏,添加背景图像并进行基本的美化。
完整代码:
package com.sammy.umass;
import android.app.ExpandableListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class DirectionsScreenActivity extends ExpandableListActivity {
ExpandableListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directions);
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
//menu.setHeaderTitle("Sample menu");
//menu.add(0, 0, 0, R.string.expandable_list_sample_action);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
String title = ((TextView) info.targetView).getText().toString();
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
Toast.LENGTH_SHORT).show();
return true;
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
/**
* A simple adapter which maintains an ArrayList of photo resource Ids.
* Each photo is displayed as an image. This adapter supports clearing the
* list of photos and adding a new photo.
*
*/
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = { " Academic Buildings", " Residential Buildings", " Dining Commons", " All Buildings A-Z" };
private String[][] children = {
//Academic Buildings
{ "Agricultural Engineering Bldg", "Army ROTC Bldg", "Arnold House", "(Studio) Arts Building" },
//Residence Halls
{ "Baker Hall", "Brett Hall", "Brooks Hall", "Brown Hall","Butterfield Hall","Cance Hall","Cashin Hall","Chadboourne Hall",
"Coolidge Hall","Crabtree Hall","Crampton Hall","Dickinson Hall","Dwight Hall","Emerson Hall","Field Hall",
"Gorman Hall","Grayson Hall","Greenough Hall","Hamlin Hall","James Hall","John Adams Hall","John Quincy Adams Hall",
"Johnson Hall","Kennedy Hall","Knowlton Hall","Leach Hall","Lewis Hall","Lincoln Apts","Mackimmie Hall","Mary Lyon Hall",
"McNamara Hall","Melville Hall","Moore Hall","North Residence A","North Residence B","North Residence C","North Residence D",
"North Village Apts","Patterson Hall","Pierpont Hall","Prince Hall","Thatcher Hall","Thoreau Hall","Van Meter Hall",
"Washington Hall","Webster Hall","Wheeler Hall"},
//Dining Commons
{ "Berkshire", "Franklin","Hampden","Hampshire","Worcester" },
{ "Agricultural Engineering Bldg", "Army ROTC Bldg", "Arnold House", "(Studio) Arts Building" }
};
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(DirectionsScreenActivity.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
public View getChildView(final int groupPosition,final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
textView.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Uri uriToOpen = getUriForView(groupPosition, childPosition);
Intent i = new Intent(Intent.ACTION_VIEW, uriToOpen);
startActivity(i);
}
private Uri getUriForView(int groupPosition, int childPosition)
{
//Academic Builds
//Residence Halls
if(groupPosition == 1 && childPosition == 0)
return Uri.parse("google.navigation:q=160+Clark+Hill+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 1)
return Uri.parse("google.navigation:q=151+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 2)
return Uri.parse("google.navigation:q=160+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 3)
return Uri.parse("google.navigation:q=92+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 4)
return Uri.parse("google.navigation:q=171+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 5)
return Uri.parse("google.navigation:q=191+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 6)
return Uri.parse("google.navigation:q=112+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 7)
return Uri.parse("google.navigation:q=110+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 8)
return Uri.parse("google.navigation:q=630+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 9)
return Uri.parse("google.navigation:q=17+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 10)
return Uri.parse("google.navigation:q=256+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 11)
return Uri.parse("google.navigation:q=151+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 12)
return Uri.parse("google.navigation:q=41+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 13)
return Uri.parse("google.navigation:q=151+Southwest+Circle+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 14)
return Uri.parse("google.navigation:q=171+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 15)
return Uri.parse("google.navigation:q=90+Butterfield+Terrace+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 16)
return Uri.parse("google.navigation:q=161+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 17)
return Uri.parse("google.navigation:q=120+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 18)
return Uri.parse("google.navigation:q=739+North+Pleasant+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 19)
return Uri.parse("google.navigation:q=660+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 20)
return Uri.parse("google.navigation:q=161+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 21)
return Uri.parse("google.navigation:q=171+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 22)
return Uri.parse("google.navigation:q=380+Thatcher+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 23)
return Uri.parse("google.navigation:q=42.38421349589919+-72.52963542938232"+"&mode=w");
if(groupPosition == 1 && childPosition == 24)
return Uri.parse("google.navigation:q=691+North+Pleasant+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 25)
return Uri.parse("google.navigation:q=21+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 26)
return Uri.parse("google.navigation:q=340+Thatcher+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 27)
return Uri.parse("google.navigation:q=341+Lincoln+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 28)
return Uri.parse("google.navigation:q=230+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 29)
return Uri.parse("google.navigation:q=43+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 30)
return Uri.parse("google.navigation:q=102+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 31)
return Uri.parse("google.navigation:q=650+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 32)
return Uri.parse("google.navigation:q=111+Southwest+Circle+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 33)
return Uri.parse("google.navigation:q=56+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 34)
return Uri.parse("google.navigation:q=58+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 35)
return Uri.parse("google.navigation:q=54+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 36)
return Uri.parse("google.navigation:q=52+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 37)
return Uri.parse("google.navigation:q=990+North+Pleasant+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 38)
return Uri.parse("google.navigation:q=204+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 39)
return Uri.parse("google.navigation:q=201+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 40)
return Uri.parse("google.navigation:q=286+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 41)
return Uri.parse("google.navigation:q=300+Thatcher+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 42)
return Uri.parse("google.navigation:q=640+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 43)
return Uri.parse("google.navigation:q=180+Clark+Hil+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 44)
return Uri.parse("google.navigation:q=181+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 45)
return Uri.parse("google.navigation:q=141+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 46)
return Uri.parse("google.navigation:q=171+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
//Dining Commons
//All Buildings
return null;
}
});
return textView;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
}
XML 代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
Hi I have this expandable list, I'm getting an error when I'm trying to connect it to a xml file using this code.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directions);
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
Using this code I get a force close when I the button that redirects to the whole java file. (Look below for full code)
Log Cat says this:
10-25 17:37:39.512: ERROR/AndroidRuntime(547):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.sammy.umass/com.sammy.umass.DirectionsScreenActivity}:
java.lang.RuntimeException: Your content must have a
ExpandableListView whose id attribute is 'android.R.id.list'
I just need remove the title bar, add an background image and pretty it up basically.
Full Code:
package com.sammy.umass;
import android.app.ExpandableListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
public class DirectionsScreenActivity extends ExpandableListActivity {
ExpandableListAdapter mAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.directions);
// Set up our adapter
mAdapter = new MyExpandableListAdapter();
setListAdapter(mAdapter);
registerForContextMenu(getExpandableListView());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
//menu.setHeaderTitle("Sample menu");
//menu.add(0, 0, 0, R.string.expandable_list_sample_action);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
String title = ((TextView) info.targetView).getText().toString();
int type = ExpandableListView.getPackedPositionType(info.packedPosition);
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
Toast.makeText(this, title + ": Child " + childPos + " clicked in group " + groupPos,
Toast.LENGTH_SHORT).show();
return true;
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
Toast.makeText(this, title + ": Group " + groupPos + " clicked", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
/**
* A simple adapter which maintains an ArrayList of photo resource Ids.
* Each photo is displayed as an image. This adapter supports clearing the
* list of photos and adding a new photo.
*
*/
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
// Sample data set. children[i] contains the children (String[]) for groups[i].
private String[] groups = { " Academic Buildings", " Residential Buildings", " Dining Commons", " All Buildings A-Z" };
private String[][] children = {
//Academic Buildings
{ "Agricultural Engineering Bldg", "Army ROTC Bldg", "Arnold House", "(Studio) Arts Building" },
//Residence Halls
{ "Baker Hall", "Brett Hall", "Brooks Hall", "Brown Hall","Butterfield Hall","Cance Hall","Cashin Hall","Chadboourne Hall",
"Coolidge Hall","Crabtree Hall","Crampton Hall","Dickinson Hall","Dwight Hall","Emerson Hall","Field Hall",
"Gorman Hall","Grayson Hall","Greenough Hall","Hamlin Hall","James Hall","John Adams Hall","John Quincy Adams Hall",
"Johnson Hall","Kennedy Hall","Knowlton Hall","Leach Hall","Lewis Hall","Lincoln Apts","Mackimmie Hall","Mary Lyon Hall",
"McNamara Hall","Melville Hall","Moore Hall","North Residence A","North Residence B","North Residence C","North Residence D",
"North Village Apts","Patterson Hall","Pierpont Hall","Prince Hall","Thatcher Hall","Thoreau Hall","Van Meter Hall",
"Washington Hall","Webster Hall","Wheeler Hall"},
//Dining Commons
{ "Berkshire", "Franklin","Hampden","Hampshire","Worcester" },
{ "Agricultural Engineering Bldg", "Army ROTC Bldg", "Arnold House", "(Studio) Arts Building" }
};
public Object getChild(int groupPosition, int childPosition) {
return children[groupPosition][childPosition];
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, 64);
TextView textView = new TextView(DirectionsScreenActivity.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
public View getChildView(final int groupPosition,final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition, childPosition).toString());
textView.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
Uri uriToOpen = getUriForView(groupPosition, childPosition);
Intent i = new Intent(Intent.ACTION_VIEW, uriToOpen);
startActivity(i);
}
private Uri getUriForView(int groupPosition, int childPosition)
{
//Academic Builds
//Residence Halls
if(groupPosition == 1 && childPosition == 0)
return Uri.parse("google.navigation:q=160+Clark+Hill+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 1)
return Uri.parse("google.navigation:q=151+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 2)
return Uri.parse("google.navigation:q=160+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 3)
return Uri.parse("google.navigation:q=92+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 4)
return Uri.parse("google.navigation:q=171+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 5)
return Uri.parse("google.navigation:q=191+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 6)
return Uri.parse("google.navigation:q=112+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 7)
return Uri.parse("google.navigation:q=110+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 8)
return Uri.parse("google.navigation:q=630+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 9)
return Uri.parse("google.navigation:q=17+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 10)
return Uri.parse("google.navigation:q=256+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 11)
return Uri.parse("google.navigation:q=151+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 12)
return Uri.parse("google.navigation:q=41+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 13)
return Uri.parse("google.navigation:q=151+Southwest+Circle+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 14)
return Uri.parse("google.navigation:q=171+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 15)
return Uri.parse("google.navigation:q=90+Butterfield+Terrace+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 16)
return Uri.parse("google.navigation:q=161+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 17)
return Uri.parse("google.navigation:q=120+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 18)
return Uri.parse("google.navigation:q=739+North+Pleasant+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 19)
return Uri.parse("google.navigation:q=660+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 20)
return Uri.parse("google.navigation:q=161+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 21)
return Uri.parse("google.navigation:q=171+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 22)
return Uri.parse("google.navigation:q=380+Thatcher+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 23)
return Uri.parse("google.navigation:q=42.38421349589919+-72.52963542938232"+"&mode=w");
if(groupPosition == 1 && childPosition == 24)
return Uri.parse("google.navigation:q=691+North+Pleasant+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 25)
return Uri.parse("google.navigation:q=21+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 26)
return Uri.parse("google.navigation:q=340+Thatcher+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 27)
return Uri.parse("google.navigation:q=341+Lincoln+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 28)
return Uri.parse("google.navigation:q=230+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 29)
return Uri.parse("google.navigation:q=43+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 30)
return Uri.parse("google.navigation:q=102+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 31)
return Uri.parse("google.navigation:q=650+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 32)
return Uri.parse("google.navigation:q=111+Southwest+Circle+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 33)
return Uri.parse("google.navigation:q=56+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 34)
return Uri.parse("google.navigation:q=58+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 35)
return Uri.parse("google.navigation:q=54+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 36)
return Uri.parse("google.navigation:q=52+Eastman+Lane+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 37)
return Uri.parse("google.navigation:q=990+North+Pleasant+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 38)
return Uri.parse("google.navigation:q=204+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 39)
return Uri.parse("google.navigation:q=201+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 40)
return Uri.parse("google.navigation:q=286+Sunset+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 41)
return Uri.parse("google.navigation:q=300+Thatcher+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 42)
return Uri.parse("google.navigation:q=640+Massachusetts+Avenue+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 43)
return Uri.parse("google.navigation:q=180+Clark+Hil+Road+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 44)
return Uri.parse("google.navigation:q=181+Fearing+Street+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 45)
return Uri.parse("google.navigation:q=141+Orchard+Hill+Drive+Amherst+MA+01003"+"&mode=w");
if(groupPosition == 1 && childPosition == 46)
return Uri.parse("google.navigation:q=171+Infirmary+Way+Amherst+MA+01003"+"&mode=w");
//Dining Commons
//All Buildings
return null;
}
});
return textView;
}
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
public int getGroupCount() {
return groups.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
}
XML CODE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 ExpandableListAdapter 时,提供的 XML 布局中需要有一个 ExpandableListView 元素,并将 id 属性设置为 android.R.id.list。你的问题出在你的directions.xml 布局上。确保在 Directions.xml 中有一个 ExpandableListView 元素,并且它的 id 属性设置为 andoird.R.id.list。您需要在directions.xml 中执行此操作:
When using an ExpandableListAdapter, the supplied XML layout needs to have an ExpandableListView element in it with the id attribute set to android.R.id.list. Your problem is in your directions.xml layout. Make sure in your directions.xml there is an ExpandableListView element and it has the id attribute set to andoird.R.id.list. You need to do this in your directoions.xml:
您必须在 xml 文件中为 ExpandableListView 添加 android 内置 id,如下所示,并使用
android:id="@+id/anyname"
删除您自己声明的 idYou will have to add android inbuilt id for ExpandableListView in xml file like below and remove the id that you declare by your own using
android:id="@+id/anyname"