I have an Android activity that displays a list of log entries (using a cursor adapter and listview). When one of the entries is touched it kicks off an intent (passed with a bundle object containing the log details as strings) to another activity. The new activity is supposed to display the details in a custom TableView xml file I created, but I can not figure out how to bind the bundle strings to the id's defined in the TextView of the TableView.
I have included most my code below so you can see what I am trying to accomplish.
ViewEntry Class:
public class ViewEntry extends Activity{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.view_list);
setTitle(R.string.view_entry_title);
TableView lv= (TableView)findViewById(R.id.viewlayout);
Bundle extras = getIntent().getExtras();
if (extras != null){
String date = extras.getString(plbDbAdapter.KEY_DATE);
String ident = extras.getString(plbDbAdapter.KEY_IDENT);
String type = extras.getString(plbDbAdapter.KEY_TYPE);
String from = extras.getString(plbDbAdapter.KEY_FROM);
String to = extras.getString(plbDbAdapter.KEY_TO);
String remark = extras.getString(plbDbAdapter.KEY_REMARK);
String[] from = new String[] { "date_h", "ident_h", "type_h", "from_h", "to_h", "remark_h"};
int[] to = new int[] { R.id.v_date, R.id.v_ident, R.id.v_type, R.id.v_from, R.id.v_to, R.id.v_remark };
ArrayAdapter details = new ArrayAdapter(this, R.layout.view_list, from, to);
setAdapter(details);
List<HashMap<String, String>> fillList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("date_h", date);
map.put("ident_h", ident);
map.put("type_h", type);
map.put("from_h", from);
map.put("to_h", to);
map.put("remark_h", remark);
fillList.add(map);
SimpleAdapter viewadapt = new SimpleAdapter(this, fillList, R.layout.view_list, from, to);
lv.setAdapter(viewadapt);
}
}
Here is view_list.xml I am trying to bind to:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/viewlayout"
android:stretchColumns="1">
<TableRow>
<TextView
android:gravity="left"
android:text="Date:"
android:padding="3dip" />
<TextView
android:id="#+id/v_date"
android:gravity="right"
android:padding="3dip" />
I know what I am trying to do isn't right but hopefully it helps illustrate my intention.
I never did find out if my approach above is possible, but I went a different direction to get the intended results. The solution I ended up using was to get the specific textview id and then set the the text with a string by using the setText() method in the code. This is probably the accepted way to approach this design issue, but it would be nice to be able to bind strings to xml instead of manipulating it with code.
I have pasted the code below for future coders reference to a solution:
public class ViewEntry extends Activity{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.view_list);
setTitle(R.string.view_entry_title);
TextView tv_date = (TextView)findViewById(R.id.tv_date);
TextView tv_ident = (TextView)findViewById(R.id.tv_ident);
TextView tv_type = (TextView)findViewById(R.id.tv_type);
TextView tv_from = (TextView)findViewById(R.id.tv_from);
TextView tv_to = (TextView)findViewById(R.id.tv_to);
TextView tv_remark = (TextView)findViewById(R.id.tv_remark);
Bundle extras = getIntent().getExtras();
if (extras != null){
String date = extras.getString(plbDbAdapter.KEY_DATE);
String ident = extras.getString(plbDbAdapter.KEY_IDENT);
String type = extras.getString(plbDbAdapter.KEY_TYPE);
String from = extras.getString(plbDbAdapter.KEY_FROM);
String to = extras.getString(plbDbAdapter.KEY_TO);
String remark = extras.getString(plbDbAdapter.KEY_REMARK);
tv_date.setText(date);
tv_ident.setText(ident);
tv_type.setText(type);
tv_from.setText(from);
tv_to.setText(to);
tv_remark.setText(remark);
}
}
Related
I am trying to display list of users from an online database
id username
1 aaaaa
2 bbbbb
3 ccccc
I'm getting the above result, now I want to add another column/TextView besides those username, perhaps firstname, or lastname,
id username lastname
1 aaaaa please
2 bbbbb help
3 ccccc me
I believe this part of the code populates the ListView
private void showEmployee(){
JSONObject jsonObject = null;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
String id = jo.getString(Config.TAG_ID);
String username = jo.getString(Config.TAG_UNAME);
//String firstname = jo.getString(Config.TAG_FNAME);
HashMap<String,String> employees = new HashMap<>();
employees.put(Config.TAG_ID,id);
employees.put(Config.TAG_UNAME,username);
// employees.put(Config.TAG_UNAME,username);
list.add(employees);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter = new SimpleAdapter(
act_viewAllusers.this, list, R.layout.list_item,
new String[]{Config.TAG_ID,Config.TAG_UNAME},
new int[]{R.id.id, R.id.username});
/*** ListAdapter adapter = new SimpleAdapter(
act_viewAllusers.this, list, R.layout.list_item,
new String[]{Config.TAG_ID,Config.TAG_UNAME,Config.TAG_FNAME},
new int[]{R.id.id, R.id.username,R.id.fname}); ***/
listView.setAdapter(adapter);
}
I have a separate Java class named Config.java which contains some URLs and JSON tags which currently I can't really understand.
Here's some part of it
//JSON Tags
public static final String TAG_JSON_ARRAY="result";
public static final String TAG_ID = "id";
public static final String TAG_UNAME = "username";
public static final String TAG_PWORD = "password";
public static final String TAG_FNAME = "firstname";
public static final String TAG_LNAME = "lastname";
public static final String TAG_BDAY = "birthday";
public static final String TAG_GENDER = "gender";
Here's the XML for my ListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http:// schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_marginRight="10dp"
android:id="#+id/id"
android:layout_width="40dp"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/fname"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/lname"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Another XML file for the ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_act_view_allusers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.bayona.lesson1.act_viewAllusers">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView" />
</LinearLayout>
Perhaps it's imposible to add another column or TextView; it's fine, but what bothers me is that I can't change the username displays.
For instance, I want to display lastname besides the id number
LinearLayout provides an android:weightSum attribute. You can set this to 4 to get even column distribution. Each TextView can be given a android:layout_weight and a android:width="0dp" in that case to fill the weight of the column.
Or you can use a GridLayout and put 4 cells in one row.
Or you can use a TableRow.
Point being, you have options. However, you shouldn't think of a ListView as a "spreadsheet". You can make each "row" as complex as you want.
Personally, maybe something like this in each row.
ID Username
Lastname, FirstName
Or don't even show the id and add # before the username...
Firstname Lastname
#Username
Just use the XML editor to create whatever layout you want.
As far as the Java code is concerned. You only have two values being set.
ListAdapter adapter = new SimpleAdapter(
act_viewAllusers.this,
list, // data
R.layout.list_item, // layout
new String[]{Config.TAG_ID,Config.TAG_UNAME}, // from[]
new int[]{R.id.id, R.id.username}); // to[]
So, you add more strings into the from array which are set into the XML id's in the to array from that layout.
Try Like This
ListAdapter adapter = new SimpleAdapter(
act_viewAllusers.this, list, R.layout.list_item,
new String[]{Config.TAG_ID,Config.TAG_UNAME,
Config.NextTAg,Config.NextTag2},
new int[]{R.id.id, R.id.username,R.id.id1,R.id.id2});
Check this if not done
try {
jsonObject = new JSONObject(JSON_STRING);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
for(int i = 0; i<result.length(); i++){
JSONObject jo = result.getJSONObject(i);
String id = jo.getString(Config.TAG_ID);
String username = jo.getString(Config.TAG_UNAME);
//-----------------
String varName=jo.getString(Config.REQ_TAG);
//-------------
//String firstname = jo.getString(Config.TAG_FNAME);
HashMap<String,String> employees = new HashMap<>();
employees.put(Config.TAG_ID,id);
employees.put(Config.TAG_UNAME,username);
//--------------
employees.put(Config.REQ_TAG,varName);
//-----------
// employees.put(Config.TAG_UNAME,username);
list.add(employees);
}
First of all, i am sorry because there is similar question that already been asked before. I've tried but it does not worked in my program. Hence, I need some help from you to help me to finish my program. Thank you.
Problem : my list cannot be click to go to next activity.
ListPending.java
public void getTable(String r) {
final ListView lv;
lv = (ListView) findViewById(R.id.lsApproval);
ArrayList<HashMap<String, String>> feedList= new ArrayList<HashMap<String, String>>();
try {
JSONArray jArray = new JSONArray(r);
JSONObject jInit = jArray.getJSONObject(0);
String valid = jInit.getString("valid");
String none="NO";
String empty="EMPTY";
TextView tv;
tv = (TextView)findViewById(R.id.tvNone);
if (valid.equals(none))
{
TextView tv1,tv2,tv3;
tv1 = (TextView)findViewById(R.id.tvSname);
tv2 = (TextView)findViewById(R.id.tvDest);
tv3 = (TextView)findViewById(R.id.tvDate);
tv.setText("\n\n\n\n\n\n" + "You do not have applicant under your approval" + "\n\n\n\n" );
tv1.setText("");
tv2.setText("");
tv3.setText("");
}
else if (valid.equals(empty))
{
TextView tv1,tv2,tv3;
tv1 = (TextView)findViewById(R.id.tvSname);
tv2 = (TextView)findViewById(R.id.tvDest);
tv3 = (TextView)findViewById(R.id.tvDate);
tv.setText("\n\n\n\n\n\n" + "No Pending List" + "\n\n\n\n" );
tv1.setText("");
tv2.setText("");
tv3.setText("");
}
else
{
String j=String.valueOf(jArray.length());
tv.setText("Have " +j+" applications need your approval");
for(int i=0; i<jArray.length();i++){
JSONObject json = jArray.getJSONObject(i);
String date = json.getString("dtfrom");
StringTokenizer tk = new StringTokenizer(date);
String dat = tk.nextToken(); // <--- yyyy-mm-dd
String staff = json.getString("staffname");
String dest = json.getString("destination");
HashMap<String, String> map = new HashMap<String, String>();
map.put("image", String.valueOf(R.mipmap.view));
map.put("staff", staff);
map.put("dest", dest);
map.put("date", dat);
feedList.add(map);
SimpleAdapter simpleAdapter = new SimpleAdapter(this, feedList, R.layout.list_pending,
new String[]{"staff", "dest","date","image"},
new int[]{R.id.tvStaff, R.id.tvDest, R.id.tvDate, R.id.ibView});
lv.setAdapter(simpleAdapter);
// React to user clicks on item
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
long id) {
Toast.makeText(ListPending.this, "try" , Toast.LENGTH_SHORT).show();
}
});
}
}
it successfully show the data from database but not clickable.
This kind of problem occur when another object on the list is either focusable or clickable. The solution is to:
Inspect your layout xml file and make sure that none of the views you are having on your list has its android:clickable set to true.
Avoid to use any clickable view like a button on your list, as this will make your list not clickable.
First of all find the views which are getting focus and not allow list to be focused and touch in all other views put
focusable=false and focusintouchMode=false in xml
and if it is still not allowing your listview to be clicked then can share your problem again.
Seem your view is not taking focus in listview.It's the issue of view when you click the list row, it is always the capture other view event. apply below property to your main layout in row file (list_pending.xml) and let me know whether its works or not?
android:descendantFocusability="blocksDescendants"
or programmatically
listView.setDescendantFocusability(ListView.FOCUS_BLOCK_DESCENDANTS);
I have a horizontal Listview. It works fine. My ArrayList eList will show a ListView going across the screen. That's great. My problem is that eList has multiple rows meaning eList might be planes, cars, and boats, or an infinite number of objects. Currently this Horizontal ListView will show only all the kinds of planes OR cars OR boats in the Database. How do show multiple or an infinite number of hListViews going down the screen vertically based upon how many object types(planes,cars,boats,tacos,people).
IN ACTIVITY
HorizontalListView hListView = (HorizontalListView) findViewById(R.id.hlistview1);
hListView.setAdapter(new ItemAdapter());
ArrayList<HashMap<String, String>> eList = controller.getAllts();
ListAdapter adapter = new SimpleAdapter(Su.this,eList,R.layout.view_m_ts, images, ins);
hListView.setAdapter(adapter);
IN DATABASE
public ArrayList<HashMap<String, String>> getAllts() {
ArrayList<HashMap<String, String>> List3;
List3 = new ArrayList<HashMap<String, String>>();
String selectQuery3 = "SELECT DISTINCT * FROM INV where p2 IS NOT NULL ORDER BY p2 COLLATE NOCASE ASC";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor3 = database.rawQuery(selectQuery3, null);
HashMap<String, String> map = new HashMap<String, String>();
if (cursor3.moveToFirst()) {
do {
map.put("iImageL", cursor3.getString(13));
map.put("p2", cursor3.getString(2));
map.put("se2", cursor3.getString(10));
map.put("te", cursor3.getString(17));
List3.add(map);
} while (cursor3.moveToNext());
}
close();
return List3;
}
IN XML
<LinearLayout
android:id="#+id/LinearViewa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:orientation="vertical" >
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/hlistview1"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_weight=".1"
android:background="#000000" />
</LinearLayout>
I'm going to assume that all objects of different types are in one SQLite table, with the type stored in one of the columns as a string, and you don't have a different table for each type.
Change your getAllts() function to return a HashMap of ArrayLists of HashMaps instead of an ArrayList of HashMaps, so that you can create multiple HorizontalListViews, one for each ArrayList of HashMaps, each one for a particular type. As you iterate through the rows returned in the cursor, get the type and check if there is already an ArrayList for it in your big HashMap, if not then create one and if so then add to the existing one:
public HashMap<String, ArrayList<HashMap<String, String>>> getAllts() {
HashMap<String, ArrayList<HashMap<String, String>>> hashMap = new HashMap<String, ArrayList<HashMap<String, String>>>();
String selectQuery3 = "SELECT DISTINCT * FROM INV where p2 IS NOT NULL ORDER BY p2 COLLATE NOCASE ASC";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor3 = database.rawQuery(selectQuery3, null);
int typeColumnIndex = 18; // <- You need to set the correct column here, possibly using cursor3.getColumnIndexOrThrow()
if (cursor3.moveToFirst()) {
do {
// create this HashMap inside the loop because we need a new one each time:
HashMap<String, String> map = new HashMap<String, String>();
ArrayList<HashMap<String, String>> List3;
// get the type of this entry as a string
String typename = cursor3.getString(typeColumnIndex);
// check if there already is an ArrayList for this type:
if(hashMap.containsKey(typename))
{
// get existing ArrayList for this type:
List3 = hashMap.get(typename);
}
else
{
// create new ArrayList for this type:
List3 = new ArrayList<HashMap<String, String>>();
hashMap.put(typename, List3);
}
map.put("iImageL", cursor3.getString(13));
map.put("p2", cursor3.getString(2));
map.put("se2", cursor3.getString(10));
map.put("te", cursor3.getString(17));
List3.add(map);
} while (cursor3.moveToNext());
}
close();
return hashMap;
}
Change your XML so that you have an empty LinearLayout in your activity XML:
<LinearLayout
android:id="#+id/LinearViewa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".1"
android:orientation="vertical" >
</LinearLayout>
and create a separate XML for the horizontal list view that you can create multiple times and add to your LinearLayout dynamically, in horiz_listview.xml or something like that. You can set up your own custom layout with the type name as a TextView header etc:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Add type name here if you like-->
<com.devsmart.android.ui.HorizontalListView
android:id="#+id/hlistview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000" />
</LinearLayout>
Then in your activity, get the massive hash map containing all the ArrayLists and iterate through it creating a HorizontalListView for each one and add it to the LinearLayout:
LinearLayout layout = (LinearLayout)findViewById(R.id.LinearViewa);
HashMap<String, ArrayList<HashMap<String, String>>> eHash = controller.getAllts();
LayoutInflater inflater = getLayoutInflater();
for(Map.Entry<String, ArrayList<HashMap<String, String>>> entry : eHash.entrySet())
{
// get the type name and ArrayList of Hashmaps for this type:
String typename = entry.getKey();
ArrayList<HashMap<String, String>> eList = entry.getValue();
// inflate a horizonal list view and add it to the layout:
View view = inflater.inflate(R.layout.horiz_listview, null, false);
layout.addView(view);
// set up the horizontal list view like before:
HorizontalListView hListView = (HorizontalListView) view.findViewById(R.id.hlistview1);
ListAdapter adapter = new SimpleAdapter(Su.this,eList,R.layout.view_m_ts, images, ins);
hListView.setAdapter(adapter);
}
If you have more HorizontalListViews than you can fit on screen then you might need to wrap your main LinearLayout in a ScrollView, however be warned that you might run into trouble with that, see this question.
I'm trying to get all the items on my listview (I've attached some image uri) and put them in the database, then get them again and load them on the listview.
What I did is: String hex = array_list.toString(); and put that hex string in the database (sqlite).
FirstFragment:
ListView lv;
ArrayList<Uri> array_list = new ArrayList<Uri>();
ArrayAdapter<Uri> array_adapter;
OnCreate..
array_adapter = new ArrayAdapter<Uri>(getActivity(), android.R.layout.simple_list_item_1, array_list);
lv = (ListView) v.findViewById(R.id.list);
lv.setAdapter(array_adapter);
OnClick..
String hex = array_list.toString();
HashMap<String, String> rcfData = new HashMap<String, String>();
rcfData.put("dateTime", hex);
DataHolder dataHolder = new DataHolder(getActivity());
dataHolder.insertData(rcfData);
Here are the items before I put them in sqlite: (Before clicking OnClick)
SecondFragment:
ListView lv2;
ArrayList<Uri> array_list2 = new ArrayList<Uri>();
ArrayAdapter<Uri> array_adapter2;
OnCreate...
array_adapter2 = new ArrayAdapter<Uri>(getActivity(), android.R.layout.simple_list_item_1, array_list2);
lv2 = (ListView) v.findViewById(R.id.list2);
lv2.setAdapter(array_adapter2);
OnClick...
Intent intent = getActivity().getIntent();
String rcfDataId = intent.getStringExtra("unique_id");
DataHolder dataHolder = new DataHolder(getActivity());
HashMap<String, String> rcfData = dataHolder.get_rcfData(rcfDataId);
if(rcfData.size() !=0) {
String s = rcfData.get("dateTime");
Uri hello = Uri.parse(s);
array_list2.add(hello);
array_adapter2.notifyDataSetChanged();
}
The problem is, when I try to load that string from sqlite to listview of the SecondFragment, it became like this: (After clicking OnClick of SecondFragment)
What I want it to be like (after clicking OnClick of SecondFragment), is like this:
How can I load it like that?
I don't know DataHolder, and I don't know whether it's really backed by an sqlite DB, but this feels like a misuse - you'd probably want to insert each of your items from your ListView as a separate row to your table.
However, if you just want a quick workaround to make it work, you could just split the string you're reading, e.g:
if(rcfData.size() !=0) {
String s = rcfData.get("dateTime");
// Remove brackets
s = s.substring(1, s.length() - 1);
// Split string and insert to ListView
for(String sPart : s.split(", ")) {
Uri hello = Uri.parse(sPart);
array_list2.add(hello);
}
array_adapter2.notifyDataSetChanged();
}
I am feeding a ListView from a database in this way (nothing special), except
COL_TXT_TRANSL2 contains html formatting:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
mCurrBookID = extras.getString("BookID");
mCurrChapterNum = extras.getString("ChapterNum");
mCurrChapterTitle = extras.getString("ChapterTitle");
mGitaDB= Central.mDB;
this.setTitle(mCurrChapterNum+"."+mCurrChapterTitle);
setContentView(R.layout.chapterdisplay);
//set chapter intro
TextView tvIntro=(TextView) findViewById(R.id.textIntro);
tvIntro.setText(Html.fromHtml(extras.getString("ChapterIntro")));
try {
String[] columns = new String[] { mGitaDB.COL_TXT_TEXT_NUM, mGitaDB.COL_TXT_TRANSL2 };
int[] to = new int[] { R.id.number_entry, R.id.title_entry };
mCursor=mGitaDB.GetGitaTexts(mCurrBookID, mCurrChapterNum);
mAdapter = new SimpleCursorAdapter(this,
R.layout.textslist_row, mCursor, columns, to);
setListAdapter(mAdapter);
}
catch (Exception e) {
String err="Error: " + e.getMessage();
Toast toast = Toast.makeText(Central.context, err, 15000);
toast.show();
}
}
Now the problem is that the text displayed in this ListView has HTML formatting.
How can I make listview display this HTML formatting? Currently it is displayed as a plain text with all tags.
Assuming the HTML is fairly simple you can run it through this method: http://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String) The resulting Spannable can be sent to a TextView in the ListView. Beware the fromHtml method is very slow and may slow down scrolling, you might want to cache the Spannables.
Define a CharSequence ArrayList, include all the elements from your database to be displayed in this arraylist as HTML. Include a personal TextView layout for the individual entities of the listView, and display the Charsequence in the list. I had made use of the following code for my app:
List<CharSequence> styledItems = new ArrayList<CharSequence>();
droidDB.open();
articles = droidDB.getAllArticleTitles(feed.feedId);
droidDB.close();
for (Article article : articles) {
styledItems.add(Html.fromHtml(article.title));
}
ArrayAdapter<CharSequence> notes =
new ArrayAdapter<CharSequence>(this, R.layout.feeds_row,styledItems);
setListAdapter(notes);
For the feeds_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"/>
Hope this helps.
My problem was similar to yours. I was reading data from file in json format, where I have objects with id and text fields. text field is html. I have resolved problem this way:
ArrayList<MyObject> myObjectsList = new ArrayList<MyObject>();
ArrayList<HashMap<String, CharSequence>> tableElements = new ArrayList<HashMap<String, CharSequence>>();
String keyword = in.getStringExtra(TAG_KEYWORD);
InputStream is = this.getResources().openRawResource(R.raw.data);
JSONParser jParser = new JSONParser();
myObjectsList = jParser.searchForObjects(is, keyword);
for (MyObject element : myObjectsList)
{
String id = Integer.toString(element.id);
CharSequence text = Html.fromHtml(element.text);
// creating new HashMap
HashMap<String, CharSequence> map = new HashMap<String, CharSequence>();
// adding each child node to HashMap key => value
map.put(TAG_ID, id);
map.put(TAG_TEXT, text);
// adding HashList to ArrayList
tableElements.add(map);
}
ListAdapter adapter = new SimpleAdapter(this,tableElements,
R.layout.search_item,
new String[] { TAG_ID, TAG_TEXT.toString()}, new int[] {
R.id.exercise_id, R.id.text });
setListAdapter(adapter);