下面列出了android.widget.ExpandableListView#setAdapter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* {@inheritDoc}
*
* @see org.emdev.ui.AbstractActionActivity#onCreateImpl(android.os.Bundle)
*/
@Override
protected void onCreateImpl(final Bundle savedInstanceState) {
setContentView(R.layout.opds);
setActionForView(R.id.opdsaddfeed);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final OPDSActivityController c = getController();
list = (ExpandableListView) findViewById(R.id.opdslist);
list.setGroupIndicator(null);
list.setChildIndicator(null);
list.setOnGroupClickListener(c);
list.setOnChildClickListener(c);
list.setAdapter(c.adapter);
this.registerForContextMenu(list);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.channel_list, container, false);
OnChildClickListener channelItemListener = new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
JSONObject channelItem = (JSONObject) adapter.getChild(groupPosition, childPosition);
channelSelected(channelItem);
return true;
}
};
ExpandableListView channelsView = (ExpandableListView) view.findViewById(R.id.channelListView);
channelsView.setEmptyView(view.findViewById(R.id.channelListProgress));
channelsView.setAdapter(adapter);
channelsView.setOnChildClickListener(channelItemListener);
PauseOnScrollListener listener = new PauseOnScrollListener(ImageLoader.getInstance(), true, true);
channelsView.setOnScrollListener(listener);
expandAll(view);
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.elvdemo2_fragment, container, false);
// get the listview
expListView = (ExpandableListView) myView.findViewById(R.id.lvExp2);
prepareListData();
listAdapter = new SimpleExpandableListAdapter(
myContext, //context
listDataGroup, // group list in the form: List<? extends Map<String, ?>>
R.layout.evl2_group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item. String[] groupFrom,
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView. int[] groupTo
listDataChild, // childData describes second-level entries. in the form List<? extends List<? extends Map<String, ?>>>
R.layout.evl2_child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item A", "Sub Item B"}, // Keys in childData maps to display.
new int[] { R.id.grp_childA, R.id.grp_childB} // Data under the keys above go into these TextViews.
);
expListView.setAdapter( listAdapter ); // setting the adapter in the list.
return myView;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.elvdemo2_fragment, container, false);
// get the listview
expListView = (ExpandableListView) myView.findViewById(R.id.lvExp2);
prepareListData();
listAdapter = new SimpleExpandableListAdapter(
myContext, //context
listDataGroup, // group list in the form: List<? extends Map<String, ?>>
R.layout.evl2_group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item. String[] groupFrom,
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView. int[] groupTo
listDataChild, // childData describes second-level entries. in the form List<? extends List<? extends Map<String, ?>>>
R.layout.evl2_child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item A", "Sub Item B"}, // Keys in childData maps to display.
new int[] { R.id.grp_childA, R.id.grp_childB} // Data under the keys above go into these TextViews.
);
expListView.setAdapter( listAdapter ); // setting the adapter in the list.
return myView;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.elvdemo1_fragment, container, false);
// get the listview
expListView = (ExpandableListView) myView.findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(myContext, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
return myView;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
ExpandableListAdapter expandableListAdapter;
HelpDataDump helpDataDump = new HelpDataDump(this);
ExpandableListView generalExpandableListView = (ExpandableListView) findViewById(R.id.generalExpandableListView);
LinkedHashMap<String, List<String>> expandableListDetail = helpDataDump.getDataGeneral();
List<String> expandableListTitleGeneral = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new ExpandableListAdapter(this, expandableListTitleGeneral, expandableListDetail);
generalExpandableListView.setAdapter(expandableListAdapter);
overridePendingTransition(0, 0);
}
/**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
* @param recentTabsManager The RecentTabsManager which provides the model data.
*/
public RecentTabsPage(Activity activity, RecentTabsManager recentTabsManager) {
mActivity = activity;
mRecentTabsManager = recentTabsManager;
mTitle = activity.getResources().getString(R.string.recent_tabs);
mThemeColor = ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.default_primary_color);
mRecentTabsManager.setUpdatedCallback(this);
LayoutInflater inflater = LayoutInflater.from(activity);
mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
mAdapter = buildAdapter(activity, recentTabsManager);
mListView.setAdapter(mAdapter);
mListView.setOnChildClickListener(this);
mListView.setGroupIndicator(null);
mListView.setOnGroupCollapseListener(this);
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
mView.addOnAttachStateChangeListener(this);
ApplicationStatus.registerStateListenerForActivity(this, activity);
// {@link #mInForeground} will be updated once the view is attached to the window.
onUpdated();
}
@Override
protected void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
setContentView(R.layout.results_expandable_list);
// get intent from main activity
Intent intent = getIntent();
// get the HashMap created in MainActivity
HashMap<String,ArrayList<String>> child = (HashMap<String,ArrayList<String>>) intent.getSerializableExtra("HashMap");
ArrayList<String> header = new ArrayList<>();
header.add("Point");
header.add("Polyline");
header.add("Polygon");
// create an expandable list view and an adapter to display in new activity.
ExpandableListView expandableListView = findViewById(R.id.expandableList);
ExpandableListAdapter expandableListAdapter = new ExpandableListAdapter(this,header,child);
expandableListView.setAdapter(expandableListAdapter);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
ExpandableListAdapter expandableListAdapter;
HelpDataDump helpDataDump = new HelpDataDump(this);
ExpandableListView generalExpandableListView = (ExpandableListView) findViewById(R.id.generalExpandableListView);
LinkedHashMap<String, List<String>> expandableListDetail = helpDataDump.getDataGeneral();
List<String> expandableListTitleGeneral = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new ExpandableListAdapter(this, expandableListTitleGeneral, expandableListDetail);
generalExpandableListView.setAdapter(expandableListAdapter);
overridePendingTransition(0, 0);
}
/**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
* @param recentTabsManager The RecentTabsManager which provides the model data.
*/
public RecentTabsPage(Activity activity, RecentTabsManager recentTabsManager) {
mActivity = activity;
mRecentTabsManager = recentTabsManager;
mTitle = activity.getResources().getString(R.string.recent_tabs);
mThemeColor = ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.default_primary_color);
mRecentTabsManager.setUpdatedCallback(this);
LayoutInflater inflater = LayoutInflater.from(activity);
mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
mAdapter = buildAdapter(activity, recentTabsManager);
mListView.setAdapter(mAdapter);
mListView.setOnChildClickListener(this);
mListView.setGroupIndicator(null);
mListView.setOnGroupCollapseListener(this);
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
mView.addOnAttachStateChangeListener(this);
ApplicationStatus.registerStateListenerForActivity(this, activity);
// {@link #mInForeground} will be updated once the view is attached to the window.
onUpdated();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View myView = inflater.inflate(R.layout.elvdemo1_fragment, container, false);
// get the listview
expListView = (ExpandableListView) myView.findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(myContext, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
return myView;
}
@SuppressLint("RestrictedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
ExpandableListAdapter expandableListAdapter;
HelpDataDump helpDataDump = new HelpDataDump(this);
ExpandableListView generalExpandableListView = (ExpandableListView) findViewById(R.id.generalExpandableListView);
LinkedHashMap<String, List<String>> expandableListDetail = helpDataDump.getDataGeneral();
List<String> expandableListTitleGeneral = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new ExpandableListAdapter(this, expandableListTitleGeneral, expandableListDetail);
generalExpandableListView.setAdapter(expandableListAdapter);
overridePendingTransition(0, 0);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_explist);
list = (ExpandableListView) findViewById(android.R.id.list);
listHandler = new ItemExpListHandler(list);
ArrayList<MenuItemDesc> menuItems = fillMenu();
listAdapter = new ItemExpListAdapter(R.layout.item, menuItems, listHandler);
fillAdapter();
list.setAdapter(listAdapter);
listManager = new ItemExpListManager(this, listHandler, true);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
LinkedHashMap<String, List<String>> expandableListDetail = buildData();
ExpandableListView generalExpandableListView = findViewById(R.id.generalExpandableListView);
generalExpandableListView.setAdapter(new HelpExpandableListAdapter(this, new ArrayList<>(expandableListDetail.keySet()), expandableListDetail));
overridePendingTransition(0, 0);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
promoExpandableListView = (ExpandableListView) findViewById(R.id.expandPromoList);
prepareItemListData();
try{
promoMaterialsListAdapter = new PromoMaterialsListAdapter(this , headerDataList, childDataList);
promoExpandableListView.setAdapter(promoMaterialsListAdapter);
} catch(Exception e){}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_info);
mBleManager = BleManager.getInstance(this);
// Init variables
restoreRetainedDataFragment();
// UI
mWaitView = findViewById(R.id.waitView);
mInfoListView = (ExpandableListView) findViewById(R.id.infoListView);
mInfoListAdapter = new ExpandableListAdapter(this, mServicesList, mCharacteristicsMap, mDescriptorsMap, mValuesMap);
mInfoListView.setAdapter(mInfoListAdapter);
BluetoothDevice device = mBleManager.getConnectedDevice();
if (device != null) {
TextView nameTextView = (TextView) findViewById(R.id.nameTextView);
boolean isNameDefined = device.getName() != null;
nameTextView.setText(device.getName());
nameTextView.setVisibility(isNameDefined ? View.VISIBLE : View.GONE);
TextView addressTextView = (TextView) findViewById(R.id.addressTextView);
final String address = String.format("%s: %s", getString(R.string.scan_device_address), device.getAddress());
addressTextView.setText(address);
onServicesDiscovered();
} else {
finish(); // Device disconnected for unknown reason
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mLayoutInflater = inflater;
ExpandableListView listView = new ExpandableListView(getActivity());
listView.setGroupIndicator(null);
if (mPackageInfo == null) {
Toast.makeText(getActivity(), R.string.app_not_installed, Toast.LENGTH_LONG).show();
} else {
listView.setAdapter(new Adapter());
}
return listView;
}
/**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
* @param recentTabsManager The RecentTabsManager which provides the model data.
*/
public RecentTabsPage(ChromeActivity activity, RecentTabsManager recentTabsManager) {
mActivity = activity;
mRecentTabsManager = recentTabsManager;
mTitle = activity.getResources().getString(R.string.recent_tabs);
mThemeColor = ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.default_primary_color);
mRecentTabsManager.setUpdatedCallback(this);
LayoutInflater inflater = LayoutInflater.from(activity);
mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
mAdapter = new RecentTabsRowAdapter(activity, recentTabsManager);
mListView.setAdapter(mAdapter);
mListView.setOnChildClickListener(this);
mListView.setGroupIndicator(null);
mListView.setOnGroupCollapseListener(this);
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
mView.addOnAttachStateChangeListener(this);
ApplicationStatus.registerStateListenerForActivity(this, activity);
// {@link #mInForeground} will be updated once the view is attached to the window.
if (activity.getBottomSheet() != null) {
View recentTabsRoot = mView.findViewById(R.id.recent_tabs_root);
ApiCompatibilityUtils.setPaddingRelative(recentTabsRoot,
ApiCompatibilityUtils.getPaddingStart(recentTabsRoot), 0,
ApiCompatibilityUtils.getPaddingEnd(recentTabsRoot),
activity.getResources().getDimensionPixelSize(
R.dimen.bottom_control_container_height));
}
onUpdated();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deployment_details);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
if(android.os.Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getResources().getColor(R.color.osm_light_green));
}
Intent intent = getIntent();
int position = intent.getIntExtra("POSITION", 0);
deployment = Deployments.singleton().get(position);
deployment.setDownloaderListener(this);
String title = deployment.title();
TextView nameTextView = (TextView)findViewById(R.id.nameTextView);
nameTextView.setText(title);
JSONObject manifest = deployment.json().optJSONObject("manifest");
if (manifest != null) {
String description = manifest.optString("description");
TextView descriptionTextView = (TextView)findViewById(R.id.descriptionTextView);
descriptionTextView.setText(description);
}
progressTextView = (TextView)findViewById(R.id.progressTextView);
progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.setMax((int)deployment.totalSize());
/**
* SETUP FOR EXPANDABLE LIST VIEW FOR MBTILES AND OSM FILES
*/
ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
FileExpandableListAdapter fileExpandableListAdapter = new FileExpandableListAdapter(this, deployment);
expandableListView.setAdapter(fileExpandableListAdapter);
/**
* FAB to initiate downloads.
*/
fab = (FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(this);
checkoutFab = (FloatingActionButton)findViewById(R.id.fab_checkout_deployment);
setFreshUIState();
}
private void loadListView(View view) {
List<String> mListDataHeader = new ArrayList<String>();
mListDataHeader.add(context.getString(R.string.fragment_config_choose));
HashMap<String, List<ExpandableListItem>> mListDataChild = new HashMap<String, List<ExpandableListItem>>();
ArrayList<ExpandableListItem> mApps = getInstalledApps();
Collections.sort(mApps, new Comparator<ExpandableListItem>() {
public int compare(ExpandableListItem o1, ExpandableListItem o2) {
return o1.getAppName().compareTo(o2.getAppName());
}
});
ExpandableListView appList = (ExpandableListView) view.findViewById(R.id.appsListView);
mListDataChild.put(mListDataHeader.get(0), mApps);
appList.setAdapter(new ExpandableListAdapter(getActivity(), mListDataHeader, mListDataChild));
}