gpt4 book ai didi

android - 在不扩展 ExpandableListActivity 的情况下使用 ExpandableListView

转载 作者:行者123 更新时间:2023-11-30 04:02:53 25 4
gpt4 key购买 nike

我已经扩展了 SherlockMapActivity,它是一个兼容库,允许在更高版本的 android 中找到类似界面的选项卡。问题是我有两个选项卡。一个 Mapview 选项卡和一个 ListView 选项卡。MapView 工作正常但 ListView 不工作。我想要一种方法来实现 expandablelistview 而无需扩展 expandablelistactivity..Expandablelistview 应该出现在 listview 选项卡下。现在的问题是 setListAdapter 方法在我的代码中未定义。请帮助。

public class MainActivity extends SherlockMapActivity implements LocationListener,ActionBar.TabListener {

private MapController mapController;
private MapView mapView;
private LocationManager locationManager;
private GeoPoint currentPoint;
private Location currentLocation = null;
private PlaceOverlay currPos;
private ViewSwitcher tswitcher;

public boolean showMiniHelp = true;

TableLayout tlayout;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);

tswitcher = (ViewSwitcher)findViewById(R.id.viewSwitcher1);


getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = getSupportActionBar().newTab();
tab1.setText("Map View");
tab1.setTabListener(this);
getSupportActionBar().addTab(tab1);

ActionBar.Tab tab2 = getSupportActionBar().newTab();
tab2.setText("List View");
tab2.setTabListener(this);
getSupportActionBar().addTab(tab2);


mapView = (MapView)findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
mapController = mapView.getController();
mapController.setZoom(17);
getLastLocation();
drawCurrPositionOverlay();
drawStores();
drawSportLocations();
animateToCurrentLocation();

//ListViewSetup

// Construct Expandable List
final String NAME = "name";
final String IMAGE = "image";
final String DATA = "data";
final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();

final HashMap<String, String> group1 = new HashMap<String, String>();
group1.put(NAME, "Group 1");
headerData.add( group1 );

final HashMap<String, String> group2 = new HashMap<String, String>();
group2.put(NAME, "Group 2");
headerData.add( group2);

final HashMap<String, String> group3 = new HashMap<String, String>();
group3.put(NAME, "Group 3");
headerData.add( group3);

final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();

final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
childData.add(group1data);

final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
childData.add(group2data);

final ArrayList<HashMap<String, Object>> group3data = new ArrayList<HashMap<String, Object>>();
childData.add(group3data);

// Set up some sample data in both groups
for( int i=0; i<10; ++i) {
final HashMap<String, Object> map = new HashMap<String,Object>();
map.put(NAME, "Child " + i );
map.put(DATA, "Data " + i);
map.put(IMAGE, getResources().getDrawable((i%3==0? R.drawable.basketball : R.drawable.supermarket)));
( i%2==0 ? group1data : group2data ).add(map);
}
final HashMap<String, Object> map = new HashMap<String,Object>();
map.put(NAME, "Child x");
map.put(DATA, "Data x");
map.put(IMAGE, getResources().getDrawable(R.drawable.tennis));
group3data.add(map);

setListAdapter( new SimpleExpandableListAdapter(
this,
headerData,
R.layout.group_row,
new String[] { NAME, DATA }, // the names of the data
new int[] { R.id.groupname }, // the text field to populate with the field data
childData,
0,
null,
new int[] {}
) {
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);

// Populate your custom view here
((TextView)v.findViewById(R.id.name)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME) );
((TextView)v.findViewById(R.id.data)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(DATA) );
((ImageView)v.findViewById(R.id.image)).setImageDrawable( (Drawable) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(IMAGE) );

return v;
}

@Override
public View newChildView(boolean isLastChild, ViewGroup parent) {
return layoutInflater.inflate(R.layout.expandable_list_item_with_image, null, false);
}
}
);
ExpandableListView list = (ExpandableListView) findViewById(android.R.id.list);
list.setOnChildClickListener(new OnChildClickListener(){
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
System.out.println("Group:"+groupPosition+", Child: "+childPosition);
return true;
}
});

最佳答案

绝对是!即使我有一个similar problem.

扩展 ExpandableListActivity 只是通过直接为您提供适配器和其他东西来帮助您。

但是您也可以在布局中定义一个 ExpandableListView 并手动声明它的所有适配器。

tutorial会帮助你。

祝你好运!

关于android - 在不扩展 ExpandableListActivity 的情况下使用 ExpandableListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12220371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com