How Would I Use A Different Row Layout In Custom Cursoradapter Based On Cursor Data?
Solution 1:
Here are two possible solutions:
(1) Use a single layout for all items, which you can adjust when binding to show as desired. The most straight-forward way would just to have the root view be a FrameLayout which contains N children for each of the different states, and you make one of them visible and all others gone when binding. Of course you want to take care to not let this cause your items to explode in the number of views they contain.
(2) Implement Adapter.getItemViewType() http://developer.android.com/reference/android/widget/Adapter.html#getItemViewType(int) to tell the list view about the different types of items you have so it will recycle the correct one.
Solution 2:
Just a few thoughts, I personnaly find the whole ListView
and CursorAdapter
combination to be a little... err... is bloated the right word? Would it just be simpler to have a ScrollView
/ LinearLayout
combination that will just add the appropriate TextView
as requested?
But as for your solution, since the user seems to be unable to change the order of the messages as they are added, you could add a ArrayList<String>
field to your custom CursorAdapter
that will keep track of whether the messages are incoming or outgoing. Something like:
private ArrayList<String> cursorMonitor; //"incoming" and "outgoing" as your options.
...and then inside wherever the ListView
gets populated just use
cursorMonitor.add(my_cursor.getString("outgoing_or_incoming"));
And then in the getView()
you can override it and use the cursorMonitor
to determine which layout you need to inflate.
Post a Comment for "How Would I Use A Different Row Layout In Custom Cursoradapter Based On Cursor Data?"