List of usage examples for android.widget ExpandableListView.OnChildClickListener ExpandableListView.OnChildClickListener
ExpandableListView.OnChildClickListener
From source file:com.messagesight.mqtthelper.PayloadViewer.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.payload);//from w ww.j av a2 s .c o m LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("payload")); expListView = (ExpandableListView) findViewById(R.id.expandableListView); Intent intent = getIntent(); String jsonString = ""; jsonString = intent.getStringExtra("json"); // System.out.println("JSON Present: "+jsonString); headers = MqttHandler.getInstance().topicsReceived; listChildren = MqttHandler.getInstance().payload; payloadAdapter = new PayloadAdapter(this, headers, listChildren); expListView.setAdapter(payloadAdapter); //set adapter // populate the listView for JSONObject Payloads if (jsonString != null) { try { JSONObject json = new JSONObject(jsonString); tempHeaders = new ArrayList<String>(); tempListChildren = new HashMap<String, List<String>>(); // headers.clear(); // listChildren.clear(); Iterator<?> keys = json.keys(); while (keys.hasNext()) { String key = (String) keys.next(); tempHeaders.add(key); List<String> val = new ArrayList<String>(); val.add(json.get(key).toString()); tempListChildren.put(key, val); } payloadAdapter = new PayloadAdapter(this, tempHeaders, tempListChildren); expListView.setAdapter(payloadAdapter); isJsonView = true; } catch (JSONException e) { } } // Listview on child click listener expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { // TODO Auto-generated method stub List<String> tempHeadersOnClick; HashMap<String, List<String>> tempListChildrenOnClick; if (isJsonView) { tempHeadersOnClick = tempHeaders; tempListChildrenOnClick = tempListChildren; } else { tempHeadersOnClick = headers; tempListChildrenOnClick = listChildren; } JSONObject json = null; try { json = new JSONObject( tempListChildrenOnClick.get(tempHeadersOnClick.get(groupPosition)).get(childPosition)); } catch (JSONException e) { } if (json != null) { Intent intent = new Intent(getApplicationContext(), PayloadViewer.class); intent.putExtra("json", json.toString()); startActivity(intent); } return false; } }); }
From source file:fyp.samoleary.WildlifePrototype2.NavDrawer.NavDrawer.java
@Override public void setContentView(final int layoutResID) { fullLayout = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_main, null); assert fullLayout != null; actContent = (FrameLayout) fullLayout.findViewById(R.id.content_frame); getLayoutInflater().inflate(layoutResID, actContent, true); super.setContentView(fullLayout); mTitle = mDrawerTitle = getTitle();//from w w w. j av a 2s.c o m //String[] navDrawerMenuItems = getResources().getStringArray(R.array.menu_items_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Get the ListView mDrawerList = (ExpandableListView) findViewById(R.id.left_drawer); // Preparing List Data prepareListDataInit(); listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); View imgView = getLayoutInflater().inflate(R.layout.header, null); mDrawerList.addHeaderView(imgView); // Setting List Adapter mDrawerList.setAdapter(listAdapter); // Listview on child click listener mDrawerList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { selectItem(groupPosition, childPosition); return false; } }); mDrawerList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { selectGroup(groupPosition); return false; } }); // set up the drawer's list view with items and click listener //mDrawerList.setAdapter(new ArrayAdapter<String>(this, // R.layout.drawer_list_item, navDrawerMenuItems)); mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // enable ActionBar app icon to behave as action to toggle nav drawer getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ mDrawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */ ) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() setUpNavDrawer(); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() imgText = (TextView) findViewById(R.id.myImageViewText); SharedPreferences settings = getSharedPreferences(LocationUtils.SHARED_PREFERENCES, 0); String name = settings.getString("name", "Click to set up Profile"); imgText.setText(name); setUpNavDrawer(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); }