Note that there are some explanatory texts on larger screens.

plurals
  1. POexpandable list and dialer
    text
    copied!<p>I have an expandable list with a header and a number. I want to complete the action using a dialer whenever the number in the list is clicked. Im stuck with the getChildView method, I need to extract a numberString from the list. I tried numberString.getChild(groupPosition, childPosition) but I have an error "Cannot refer to a non-final variable groupPosition inside an inner class defined in a different method" Anyone have an idea how to do that ? thanks for help. Here is my code:</p> <pre><code> public class ContactActivity extends ExpandableListActivity { ExpandableListAdapter mAdapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set up our adapter mAdapter = new MyExpandableListAdapter(); setListAdapter(mAdapter); // getExpandableListView().setOnChildClickListener(this); } public class MyExpandableListAdapter extends BaseExpandableListAdapter { // Sample data set. children[i] contains the children (String[]) for groups[i]. private String[] groups = { "General Enquiries", "Admissions Office"}; private String[][] children = { { "+353-91-753161" }, { "+353-91-742305", "+353-91-742262"} }; public Object getChild(int groupPosition, int childPosition) { return children[groupPosition][childPosition]; } public long getChildId(int groupPosition, int childPosition) { return childPosition; } public int getChildrenCount(int groupPosition) { return children[groupPosition].length; } public TextView getGenericView() { // Layout parameters for the ExpandableListView AbsListView.LayoutParams lp = new AbsListView.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 64); TextView textView = new TextView(ContactActivity.this); textView.setLayoutParams(lp); // Center the text vertically textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT); // Set the text starting position textView.setPadding(70, 0, 0, 0); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,20); return textView; } public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { TextView textView = getGenericView(); textView.setText(getChild(groupPosition, childPosition).toString()); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,15); textView.setOnClickListener(new View.OnClickListener(){ public void onClick(View view){ MyExpandableListAdapter numberString = new MyExpandableListAdapter(); numberString.getChild(groupPosition, childPosition); Uri number = Uri.parse("tel:" + numberString); Intent dial = new Intent(Intent.ACTION_CALL, number); startActivity(dial); } }); return textView; } public Object getGroup(int groupPosition) { return groups[groupPosition]; } public int getGroupCount() { return groups.length; } public long getGroupId(int groupPosition) { return groupPosition; } public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { TextView textView = getGenericView(); textView.setText(getGroup(groupPosition).toString()); return textView; } public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } public boolean hasStableIds() { return true; } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload