我在类OrderMenu中的ExpandableListView setAdapter()方法遇到问题。它告诉我这是不明确的(对于类型ExpandableListView,方法setAdapter(ListAdapter)是不明确的)。
package com.ucapp.uppercrustapp;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.os.Build;
public class OrderMenu extends ActionBarActivity {
//expandable list view variable
ExpandableListView exv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); //Remove action bar from screen
setContentView(R.layout.activity_order_menu);
//find resource expandable list view by ID
exv = (ExpandableListView)findViewById(R.id.itemsList);
//add an adapter that provides data to the list
exv.setAdapter(new MyAdapter(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.order_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}//end Order menu class
适配器类:
package com.ucapp.uppercrustapp;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
public class MyAdapter extends BaseExpandableListAdapter implements ListAdapter {
//context variable
private Context context;
//String Arrays
String [] parentList = {"Breakfats","Lunch"};
String [][] childList = {
{"Pancake"},
{"Sandwich"}
};
public MyAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return parentList.length;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return childList[groupPosition].length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView tv = new TextView(context);
tv.setText(parentList[groupPosition]);
return tv;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView tv = new TextView(context);
tv.setText(childList[groupPosition][childPosition]);
return tv;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isEnabled(int position) {
// TODO Auto-generated method stub
return false;
}
}
还有我的OrderMenu XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context="com.ucapp.uppercrustapp.OrderMenu" >
<ImageView
android:id="@+id/uc_logo"
android:layout_width="fill_parent"
android:layout_height="242dp"
android:layout_alignParentLeft="true"
android:baselineAlignBottom="false"
android:contentDescription="@string/uc_logo"
android:focusable="false"
android:scaleType="centerCrop"
android:src="@drawable/uc_logo_3" />
<Button
android:id="@+id/backBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/uc_logo"
android:text="@string/backBTN" />
<Button
android:id="@+id/checkoutBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/backBTN"
android:layout_alignBottom="@+id/backBTN"
android:layout_alignParentRight="true"
android:text="@string/checkoutBTN" />
<ExpandableListView
android:id="@+id/itemsList"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
</ExpandableListView>
最佳答案
尝试exv.setAdapter((ExpandableListAdapter)new MyAdapter(this));
要么public class MyAdapter extends BaseExpandableListAdapter {...}
没有实现ListAdapter