I'm trying to figure out if it is possible to launch an intent within an ExpandableListView. Basically one of the "Groups" is Phone Number and its child is the number. I want the user to be able to click it and have it automatically call that number. Is this possible? How?
Here is my code to populate the ExpandableListView using a Map called "data".
ExpandableListView myList = (ExpandableListView) findViewById(R.id.myList);
//ExpandableListAdapter adapter = new MyExpandableListAdapter(data);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
Iterator it = data.entrySet().iterator();
while (it.hasNext())
{
//Get the key name and value for it
Map.Entry pair = (Map.Entry)it.next();
String keyName = (String) pair.getKey();
String value = pair.getValue().toString();
//Add the parents -- aka main categories
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put("NAME", keyName);
//Add the child data
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put("NAME", value);
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
mContext,
groupData,
R.layout.exp_list_parent,
new String[] { "NAME", "IS_EVEN" },
new int[] { R.id.rowText1, R.id.rowText2 },
childData,
R.layout.exp_list_child,
new String[] { "NAME", "IS_EVEN" },
new int[] { R.id.rowText3, R.id.rowText4}
);
myList.setAdapter(mAdapter);
You can add an OnChildClickListener to your expandable list view. When OnChildClick is called, you have the group and child position, so you should be able to figure out which phone number was clicked.
Then you just need to fire off an intent to make the phone call, i.e.:
Intent intent = new Intent(Intent.CALL_ACTION);
intent.setData(Uri.parse("tel:+436641234567"));
startActivity(intent);
Related
I have a code here that displays data in custom listview from my database
List<Map<String, String>> data1 = new ArrayList<Map<String, String>>();
while (data.moveToNext()) {
Map<String, String> datum = new HashMap<String, String>(5);
datum.put("Customer Name", data.getString(0));
datum.put("Address", data.getString(1));
datum.put("Remarks", data.getString(2));
datum.put("Date", data.getString(3));
datum.put("Code", data.getString(4));
data1.add(datum);
}
adapter = new SimpleAdapter(getActivity(), data1,
R.layout.listview_plan,
new String[]{"Customer Name", "Address", "Remarks", "Date", "Code"},
new int[]{R.id.list_name,
R.id.list_address,
R.id.list_remarks,
R.id.list_date, R.id.list_code});
listView.setAdapter(adapter);
count.setText("" + listView.getAdapter().getCount());
My question is during population I want to add some condition like hiding a textview. How can I do that?
sample
ListView.Populate{
if (data.getString(3)) == null) {
//Hide the label on that row
}
}
My target is to hide a specific textview in listview
Here I am creating a list of items using expandable list view.
Here is the code for the list items.
public class ExpandableListDataPump {
public static HashMap<String, List<String>> getData() {
HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
List<String> business = new ArrayList<String>();
business.add("India");
List<String> entertainment = new ArrayList<String>();
entertainment.add("Brazil");
List<String> gaming = new ArrayList<String>();
gaming.add("United States");
List<String> general = new ArrayList<String>();
general.add("United States");
List<String> music = new ArrayList<String>();
music.add("United States");
List<String> sciandnat = new ArrayList<String>();
sciandnat.add("United States");
List<String> sports = new ArrayList<String>();
sports.add("United States");
List<String> technology = new ArrayList<String>();
technology.add("United States");
expandableListDetail.put("BUSINESS", business);
expandableListDetail.put("ENTERTAINMENT",entertainment);
expandableListDetail.put("GAMING",gaming);
expandableListDetail.put("GENERAL", general);
expandableListDetail.put("MUSIC", music);
expandableListDetail.put("SCIENCE AND NATURE", sciandnat);
expandableListDetail.put("SPORTS", sports);
expandableListDetail.put("TECHNOLOGY", technology);
return expandableListDetail;
}
}
I want the list to be displayed in the order as BUSINESS,ENTERTAINMENT,GAMING,GENERAL,MUSIC,SCIENCE AND NATURE,SPORTS,TECHNOLOGY
so I have given here like what I want the items to be in that order
expandableListDetail.put("BUSINESS", business);
expandableListDetail.put("ENTERTAINMENT",entertainment);
expandableListDetail.put("GAMING",gaming);
expandableListDetail.put("GENERAL", general);
expandableListDetail.put("MUSIC", music);
expandableListDetail.put("SCIENCE AND NATURE", sciandnat);
expandableListDetail.put("SPORTS", sports);
expandableListDetail.put("TECHNOLOGY", technology);
but when I see the output it is like this
output image
Why??
but when i see the output it is like this, why
Because you are using a HashMap as Map fro your dataset, which doesn't preserve the inserti order of its items. Use a LinkedHashMap which preserves the insertion order. Change
HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
with
Map<String, List<String>> expandableListDetail = new LinkedHashMap<String, List<String>>();
I need to display 5 different groups of strings. Some of the items in these strings are one or two sentences long. I was considering using an expandablelistview. The user could click one of the 5 categories and it would open up with all the strings.
Is there a string cut off for strings in an expandablelistview and listview or a way to display more then a sentence of information? I don't want the strings to get cut off. Note, I am not asking about the number of elements in the list.
public class HappyStuff extends ExpandableListActivity {
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";
private ExpandableListAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.somelayout);
List<Map<String, String>> someData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> someotherData = new ArrayList<List<Map<String, String>>>();
//FROM HERE
for (int i = 0; i < 1; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
someData.add(curGroupMap);
curGroupMap.put(NAME, "It's a wonderful life");
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children3 = new ArrayList<Map<String, String>>();
{
Map<String, String> curChildMap = new HashMap<String, String>();
children3.add(curChildMap);
curChildMap.put(IS_EVEN, "And it's a beautiful day in the neighborhood");
}
someotherdata.add(children3);
}
//TO HERE
//YOU CAN JUST KEEP ON ADDING NEW INSTANCES
supermagnificentAdapter = new SimpleExpandableListAdapter(
this,
someData,
R.layout.somespecialtypeoflayout,
new String[] { NAME, IS_EVEN },
new int[] { R.id.text1, R.id.text2 },
childData,
R.layout.rowsimpleitemlist2,
new String[] { NAME, IS_EVEN },
new int[] { R.id.text1, R.id.text2 }
);
setListAdapter(supermagnificentAdapter);
}
}
if supplier id is !=0 then
if(user.getString("iSupplierID")!="0")
{
String SUPPLIER_NAME=user.getString(TAG_NAME);
String PRIMARY_SERVICE_CATEGORY = user.getString(TAG_PRIMARY);
String SECONDARY_SERVICE_CATEGORY = user.getString(TAG_SECONDARY);
String SOURCE_DIRECTORY_TYPE = user.getString(TAG_SOURCE);
Adding value HashMap key => value
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_NAME, SUPPLIER_NAME);
map.put(TAG_PRIMARY, PRIMARY_SERVICE_CATEGORY);
map.put(TAG_SECONDARY, SECONDARY_SERVICE_CATEGORY);
map.put(TAG_SOURCE, SOURCE_DIRECTORY_TYPE);
supplierlist.add(map);
creating an id for list view
lv=(ListView)findViewById(R.id.listView1);
listview adapter
ListAdapter adapter = new SimpleAdapter(SupplierDetails.this, supplierlist,
R.layout.list_view,
new String[] { TAG_NAME,TAG_PRIMARY,TAG_SECONDARY, TAG_SOURCE }, new int[] {
R.id.primary,R.id.secondary, R.id.source});
lv.setAdapter(adapter);
I am using an expandable listview. The code is as follows and it works fine. But the problem is in a child of a group I want to put some big information, but it is not showing that. It is just showing 1 line.
public class list1 extends ExpandableListActivity {
private static final String NAME = "name";
private static final String time = "time";
private static final String IS_EVEN = "IS_EVEN";
private ExpandableListAdapter mAdapter;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
final HashMap<String, String> info1 = new HashMap<String, String>();
info1.put(NAME, "information");
groupData.add(info1);
final HashMap<String, String> tt = new HashMap<String, String>();
tt.put(NAME, "time");
groupData.add(tt);
final HashMap<String, String> loc = new HashMap<String, String>();
loc.put(NAME, "Location");
groupData.add(loc);
List<Map<String, String>> childreninfo = new ArrayList<Map<String, String>>();
List<Map<String, String>> childrentime = new ArrayList<Map<String, String>>();
List<Map<String, String>> childrenloc = new ArrayList<Map<String, String>>();
Map<String, String> infochild = new HashMap<String, String>();
childreninfo.add(infochild);
infochild.put(NAME, "asnflabfbalv j;ajf;adf ;j; asjfsap sdjosdjosjdos dosjdosjdosjdos osfjsodfjsofjso osjfosjdfosjf s jsofjsojdsod jdosjdsosod jdsofjsojdfsofd jfosjdfsofjsof odjfsojfsodjosdjsod sojdosjdso djosjdosjds djsodj");
Map<String, String> timechild = new HashMap<String, String>();
childrentime.add(timechild);
timechild.put(NAME, "Childtime " + 1);
Map<String, String> locchild = new HashMap<String, String>();
childrenloc.add(locchild);
locchild.put(NAME, "Childloc " + 1);
childData.add(childreninfo);
childData.add(childrentime);
childData.add(childrenloc);
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
this,
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME,time },
new int[] { android.R.id.text1, android.R.id.text2 },
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 }
);
setListAdapter(mAdapter);
}
}
in this infochild.put(); it is putting very big information, but here it is showing only 1st line of information.
How can I fix this to show all the information?
This happens because android.R.layout.simple_expandable_list_item_2 defines TwoLineListItem.
You should provide a simple layout with a single TextView instead:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
...
/>
Or you may also try using android.R.layout.simple_expandable_list_item_1.