How to populate a spinner with ORMLite returned list of objects

472 views
Skip to the first unread message

Robert Bui

unread,
18 Dec 2011, 02:56:5618/12/2011
to ORMLite Android Users
Hello,
Anyone know a way to populate a spinner with the ORMLite returned
list of objects. I have read the post about
OrmLiteSimpleCursorAdapter,
http://groups.google.com/group/ormlite-android/browse_thread/thread/3f42cd6ce5ddd9b3/74681562dc5ecf73?#74681562dc5ecf73,
but I don't understand how to use it. Also, is this going to be part
of ORMLite?

Any help would be appreciated.

Regards,

Robert

Robert Bui

unread,
13 Jan 2012, 02:16:2613/01/2012
to ORMLite Android Users
I managed to resolve this issue, below are my code.
Basically, populate a ArrayAdapter with the list of objects from the
queryForAll then inside OnItemSelectedListener get the select objected
from the position inside the adapter.


private void refreshScreen()
{
try
{
publicationDao = this.getHelper().getPublicationDao();
Spinner spinner =
(Spinner)aq.id(R.id.publicationSpinner).getSpinner();
List<Publication> publicationList = publicationDao.queryForAll();
final ArrayAdapter<Publication> adapter =
new ArrayAdapter<Publication>(
this,
android.R.layout.simple_spinner_item);

for (Publication publication : publicationList) {
adapter.add(publication);
}
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> parent,
View view,
int position,
long id) {
Publication publication =
adapter.getItem(position);
currentPublication = publication;
showPublicationDetail(currentPublication);
}
public void onNothingSelected(AdapterView<?>
parent) {
}
}
);
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


On Dec 18 2011, 6:56 pm, Robert Bui <robertqh...@gmail.com> wrote:
> Hello,
>    Anyone know a way to populate a spinner with the ORMLite returned
> list of objects. I have read the post about
> OrmLiteSimpleCursorAdapter,http://groups.google.com/group/ormlite-android/browse_thread/thread/3...,
Reply all
Reply to author
Forward
0 new messages