I get a list of objects from database, meanwhile it’s two parameters – title and datetime.
I’ve created a listView in main.xml and item.xml for each row in the list.
I get all list, place it to ArrayList (Map (String, Object)) and array list has all data when is placed into the adapter.
private void getAllNotesLocal () {
manager = new NotesManager(this);
lstNotes = manager.getAllNotes();
ArrayList<Map<String, Object>> _notesList = new ArrayList<Map<String, Object>>(lstNotes.size());
Map<String, Object> _map;
for (NoteObj currNote : lstNotes) {
_map = new HashMap<String, Object>();
_map.put(Constants.ATTRIBUTE_NAME_TITLE, currNote.getName());
_map.put(Constants.ATTRIBUTE_NAME_DATE, currNote.getDate());
_notesList.add(_map);
}
String[] from = {Constants.ATTRIBUTE_NAME_TITLE, Constants.ATTRIBUTE_NAME_DATE};
int[] to = { R.id.tv_name, R.id.tv_date};
SimpleAdapter sAdapter = new SimpleAdapter(this, _notesList, R.layout.item, from, to);
lvAllNotes = getListView();
lvAllNotes.setAdapter(sAdapter);
}
But nothing happens in the screen.
When i use arrayAdapter everythin is OK except there is only one parameter I could place into each row.
The code that is works is here:
ListView lvAllNotes = = getListView();
ArrayList<NoteObj> lstNotes = manager.getAllNotes();
ArrayAdapter<NoteObj> adapter = new ArrayAdapter<NoteObj>(this, R.layout.item, R.id.tv_name, lstNotes);
setListAdapter(adapter);
The main.xml:
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
The item.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp" >
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|left"
android:layout_marginLeft="5dp"
android:ellipsize="end"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="@string/empty"
android:textSize="18sp" />
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="5dp"
android:text="@string/empty"
android:textSize="9sp"
android:textStyle="italic" >
</TextView>
</FrameLayout>
I think the frame layout is the problem.
This is because frame layout just shows a single view to the user.All the remaining views will be hidden below the first layout.
So that the problem
Any how happy to know that my solution helped in solving the issue.