List of usage examples for android.widget ExpandableListView setOnChildClickListener
public void setOnChildClickListener(OnChildClickListener onChildClickListener)
From source file:com.jbirdvegas.mgerrit.PatchSetViewerFragment.java
private void init() { View currentFragment = this.getView(); ExpandableListView mListView = (ExpandableListView) currentFragment.findViewById(R.id.commit_cards); disconnectedView = currentFragment.findViewById(R.id.disconnected_view); sIsLegacyVersion = !Config.isDiffSupported(mParent); mAdapter = new CommitDetailsAdapter(mParent); mListView.setAdapter(mAdapter);//ww w.ja v a 2 s. c o m // Child click listeners (relevant for the changes cards) mListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); mFilesCAB = new FilesCAB(mParent, !sIsLegacyVersion); mAdapter.setContextualActionBar(mFilesCAB); mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ExpandableListView listView = (ExpandableListView) parent; long pos = listView.getExpandableListPosition(position); int groupPos = ExpandableListView.getPackedPositionGroup(pos); int childPos = ExpandableListView.getPackedPositionChild(pos); if (!mAdapter.isLongClickSupported(groupPos, childPos)) { return false; } // In case this is a group view and does not have the change number tagged view.setTag(R.id.changeID, mSelectedChange); FilesCAB.TagHolder holder = new FilesCAB.TagHolder(view, mContext, groupPos, childPos >= 0); // Set the title to be shown in the action bar if (holder.filePath != null) { mFilesCAB.setTitle(holder.filePath); } else { String s = mParent.getResources().getString(R.string.change_detail_heading); mFilesCAB.setTitle(String.format(s, holder.changeNumber.intValue())); } mFilesCAB.setActionMode(getActivity().startActionMode(mFilesCAB)); ActionMode actionMode = mFilesCAB.getActionMode(); // Call requires API 14 (ICS) actionMode.setTag(holder); view.setSelected(true); return true; } }); mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // This is only valid for the changed files group int childItemType = mAdapter.getChildType(groupPosition, childPosition); if (childItemType != CommitDetailsAdapter.Cards.CHANGED_FILES.ordinal()) { return false; } // View the diff and close the CAB if a change diff could be viewed boolean diffLaunched = PatchSetChangesCard.onViewClicked(mParent, v); if (diffLaunched) { ActionMode mode = mFilesCAB.getActionMode(); if (mode != null) mode.finish(); } return diffLaunched; } }); mUrl = new GerritURL(); Button retryButton = (Button) currentFragment.findViewById(R.id.btn_retry); retryButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (sIsLegacyVersion) sendRequest(GerritService.DataType.Commit); else sendRequest(GerritService.DataType.LegacyCommitDetails); } }); if (getArguments() == null) { /** This should be the default value of {@link ChangeListFragment.mSelectedStatus } */ setStatus(JSONCommit.Status.NEW.toString()); loadChange(true); } else { Bundle args = getArguments(); setStatus(args.getString(STATUS)); String changeid = args.getString(CHANGE_ID); mChangeNumber = args.getInt(CHANGE_NO); if (changeid != null && !changeid.isEmpty()) { loadChange(changeid); } } mEventBus = EventBus.getDefault(); }
From source file:com.money.manager.ex.home.MainActivity.java
private void createExpandableDrawer() { UIHelper uiHelper = new UIHelper(this); int iconColor = uiHelper.getSecondaryTextColor(); // Menu./*w w w . j a v a2 s. c o m*/ final ArrayList<DrawerMenuItem> groupItems = getDrawerMenuItems(); final ArrayList<Object> childItems = new ArrayList<>(); // Home childItems.add(null); // Open Database. Display the recent db list. ArrayList<DrawerMenuItem> childDatabases = getRecentDatabasesDrawerMenuItems(); childItems.add(childDatabases); // Synchronization if (new SyncManager(this).isActive()) { childItems.add(null); } // Entities ArrayList<DrawerMenuItem> childTools = new ArrayList<>(); // manage: account childTools.add(new DrawerMenuItem().withId(R.id.menu_account).withText(getString(R.string.accounts)) .withIconDrawable(uiHelper.getIcon(MMXIconFont.Icon.mmx_temple).color(iconColor))); // manage: categories childTools.add(new DrawerMenuItem().withId(R.id.menu_category).withText(getString(R.string.categories)) .withIconDrawable(uiHelper.getIcon(MMXIconFont.Icon.mmx_tag_empty).color(iconColor))); // manage: currencies childTools.add(new DrawerMenuItem().withId(R.id.menu_currency).withText(getString(R.string.currencies)) .withIconDrawable(uiHelper.getIcon(GoogleMaterial.Icon.gmd_euro_symbol).color(iconColor))); // manage: payees childTools.add(new DrawerMenuItem().withId(R.id.menu_payee).withText(getString(R.string.payees)) .withIconDrawable(uiHelper.getIcon(GoogleMaterial.Icon.gmd_group).color(iconColor))); childItems.add(childTools); // Recurring Transactions childItems.add(null); // Budgets childItems.add(null); // Asset Allocation //if (BuildConfig.DEBUG) <- this was used to hide the menu item while testing. childItems.add(null); // Search transaction childItems.add(null); // reports childItems.add(null); // Settings childItems.add(null); // Donate childItems.add(null); // Help childItems.add(null); // Adapter. final ExpandableListView drawerList = (ExpandableListView) findViewById(R.id.drawerExpandableList); DrawerMenuGroupAdapter adapter = new DrawerMenuGroupAdapter(this, groupItems, childItems); drawerList.setAdapter(adapter); // set listener on item click drawerList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (mDrawer == null) return false; // if the group has child items, do not e. ArrayList<String> children = (ArrayList<String>) childItems.get(groupPosition); if (children != null) return false; // Highlight the selected item, update the title, and close the drawer drawerList.setItemChecked(groupPosition, true); // You should reset item counter mDrawer.closeDrawer(mDrawerLayout); // check item selected final DrawerMenuItem item = (DrawerMenuItem) drawerList.getExpandableListAdapter() .getGroup(groupPosition); if (item != null) { new Handler().postDelayed(new Runnable() { @Override public void run() { // execute operation onDrawerMenuAndOptionMenuSelected(item); } }, 200); } return true; } }); drawerList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (mDrawer == null) return false; mDrawer.closeDrawer(mDrawerLayout); ArrayList<Object> children = (ArrayList) childItems.get(groupPosition); final DrawerMenuItem selectedItem = (DrawerMenuItem) children.get(childPosition); if (selectedItem != null) { new Handler().postDelayed(new Runnable() { @Override public void run() { onDrawerMenuAndOptionMenuSelected(selectedItem); } }, 200); return true; } else { return false; } } }); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * This functions creates a dialog which allows the user to export different * map layers.//from w w w .j av a 2s .c om * * @param ActivityContext * The context of the current activity. * @return True if the export succeeded, false otherwise. */ public boolean exportMapLayerToUser(Context activityContext) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.dialog_export_metadata, (null)); Button downloadButton = (Button) view.findViewById(R.id.metadataDownloadButton); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); final AlertDialog builder = new AlertDialog.Builder(activityContext).create(); builder.setTitle(R.string.map_export_metadata_title); builder.setView(view); final AtomicReference<String> selectedHeader = new AtomicReference<String>(); final AtomicReference<String> selectedFormat = new AtomicReference<String>(); final ExpandableListView expListView = (ExpandableListView) view .findViewById(R.id.exportMetadataMapServices); final List<String> listDataHeader = new ArrayList<String>(); final HashMap<String, List<String>> listDataChild = new HashMap<String, List<String>>(); final Map<String, String> nameToApiNameResolver = new HashMap<String, String>(); JSONArray availableSubscriptions = getSharedCacheOfAvailableSubscriptions(); if (availableSubscriptions == null) { availableSubscriptions = authenticatedGetRequestToBarentswatchAPIService( getString(R.string.my_page_geo_data_service)); setSharedCacheOfAvailableSubscriptions(availableSubscriptions); } for (int i = 0; i < availableSubscriptions.length(); i++) { try { JSONObject currentSub = availableSubscriptions.getJSONObject(i); nameToApiNameResolver.put(currentSub.getString("Name"), currentSub.getString("ApiName")); listDataHeader.add(currentSub.getString("Name")); List<String> availableDownloadFormatsOfCurrentLayer = new ArrayList<String>(); JSONArray availableFormats = currentSub.getJSONArray("Formats"); for (int j = 0; j < availableFormats.length(); j++) { availableDownloadFormatsOfCurrentLayer.add(availableFormats.getString(j)); } listDataChild.put(listDataHeader.get(i), availableDownloadFormatsOfCurrentLayer); System.out .println("item: " + currentSub.getString("Name") + ", " + currentSub.getString("ApiName")); } catch (JSONException e) { e.printStackTrace(); Log.d("ExportMapLAyerToUser", "Invalid JSON returned from API CALL"); return false; } } final ExpandableListAdapter listAdapter = new ExpandableListAdapter(activityContext, listDataHeader, listDataChild); expListView.setAdapter(listAdapter); // Listview on child click listener expListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { selectedHeader.set(nameToApiNameResolver.get(listDataHeader.get(groupPosition))); selectedHeader.set(listDataHeader.get(groupPosition)); selectedFormat.set(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition)); LinearLayout currentlySelected = (LinearLayout) parent.findViewWithTag("currentlySelectedRow"); if (currentlySelected != null) { currentlySelected.getChildAt(0).setBackgroundColor(Color.WHITE); currentlySelected.setTag(null); } ((LinearLayout) v).getChildAt(0).setBackgroundColor(Color.rgb(214, 214, 214)); v.setTag("currentlySelectedRow"); return true; } }); downloadButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new DownloadMapLayerFromBarentswatchApiInBackground() .execute(nameToApiNameResolver.get(selectedHeader.get()), selectedFormat.get()); builder.dismiss(); } }); cancelButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { builder.dismiss(); } }); builder.setCanceledOnTouchOutside(false); builder.show(); return true; }