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.
Related
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);
}
}
I have a working expandablelistview code, which works fine as a standalone.
I have another working code for sliding tab views which I wrote separately.
Both these were written after going thru a number of blogs, android dev and stackoverflow questions.
When I try to combine and put the expandable listview in one of the fragments, I end up with an error, I am unable to resolve.
Here's the code from the Fragment piece:
public class Fragment1 extends Fragment {
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);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < 10; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "Group " + i);
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 2; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Child " + j);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
}
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
getActivity(),
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
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);
}
}`
I keep getting error on the last line: 'The method setListAdapter(ExpandableListAdapter) is undefined for the type Fragment1'.
The rest of the code shows no error.
Please help. How can I correct this problem.
I was able to solve the problem myself.. For future reference, here's the code. Might be messy and needs cleanup, but it works for now!
public class HotDeals extends Fragment {
private ExpandableListAdapter mAdapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.saved_tabs, null);
return v;
}
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < 10; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "Group " + i);
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 2; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Child " + j);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
}
childData.add(children);
}
ExpandableListView lv = (ExpandableListView) getActivity().findViewById(R.id.list);
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
getActivity(),
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
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 }
);
lv.setAdapter(mAdapter);
}
}
#Divers & #Dixit - Thanx.
Fragment do not contains method setListAdapter. ListFragment do. You have to extend your fragment from this class to solve this problem.
This post is almost 2 years old, but no answer in this page is a relevant one.
to answer PO question,
The method setListAdapter(ExpandableListAdapter) is undefined for the type Fragment1
It's because setListAdapter is a method of ListFragment or ListActivity which is waiting for a ListAdapter or its subclasses as argument. You get this error because you gave it a ExpandableListAdapter which does not implement the ListAdapter interface.
Hope this will help someone.
I try to retrieve all data from database and put into arraylist of hasmap
but i get only the last record of table.
here is my code :
databaseAirport myDbHelper = new databaseAirport(this);
myDbHelper.open();
Cursor c = myDbHelper.selectAll();
HashMap<String, String> map = new HashMap<String, String>();
ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String,String>>();
if(c!=null && c.moveToFirst())
{
do
{
map.put(KEY_ACODE, c.getString(5).toString());
map.put(KEY_FNUM, c.getString(6).toString());
map.put(KEY_STOP_1, c.getString(8).toString());
map.put(KEY_FTIME, c.getString(7).toString());
map.put(KEY_REMARK, c.getString(10).toString());
map.put(KEY_REM_COM, c.getString(11).toString());
dataList.add(map);
}while(c.moveToNext());
}
At the end, my dataList(map) retrieve the last record only...
Can anyone help me please..
Move this line as follow: HashMap<String, String> map = new HashMap<String, String>();
databaseAirport myDbHelper = new databaseAirport(this);
myDbHelper.open();
Cursor c = myDbHelper.selectAll();
HashMap<String, String> map;
ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String,String>>();
if(c!=null ){
c.moveToFirst();
while( cur.isAfterLast() == false )
{
map = new HashMap<String, String>(); // <---- moved here
map.put(KEY_ACODE, c.getString(5).toString());
map.put(KEY_FNUM, c.getString(6).toString());
map.put(KEY_STOP_1, c.getString(8).toString());
map.put(KEY_FTIME, c.getString(7).toString());
map.put(KEY_REMARK, c.getString(10).toString());
map.put(KEY_REM_COM, c.getString(11).toString());
dataList.add(map);
c.moveToNext();
}
}
Change your code like this
databaseAirport myDbHelper = new databaseAirport(this);
myDbHelper.open();
Cursor c = myDbHelper.selectAll();
ArrayList<HashMap<String, String>> dataList = new ArrayList<HashMap<String,String>>();
while(c.moveToNext());
{
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_ACODE, c.getString(5).toString());
map.put(KEY_FNUM, c.getString(6).toString());
map.put(KEY_STOP_1, c.getString(8).toString());
map.put(KEY_FTIME, c.getString(7).toString());
map.put(KEY_REMARK, c.getString(10).toString());
map.put(KEY_REM_COM, c.getString(11).toString());
dataList.add(map);
}
I wonder how to get value from database into Expandable List via cursor
public class SmplExpandable 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);
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < 10; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(NAME, "Group " + i);
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 3; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(NAME, "Child " + j);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "This child is even" : "This child is odd");
}
childData.add(children);
}
// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
this,
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
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);
}
}
Why don't you use the SimpleCursorTreeAdapter : http://developer.android.com/reference/android/widget/SimpleCursorTreeAdapter.html
By the way,if anyone has a good tutorial about SimpleCursorTreeAdapter,please share with us.
Here is sample from Android API demo ExpandableList2 You can import code by create sample project
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);