DibaToner DibaToner - 4 months ago 24
Android Question

OrmLite get value from listView with Adapter

When I want to get a name of list which I pressed, I get "com.example.oleksandr.dream.DB.DreamDetails@528f8a90". How can I get a String value from my list? The problem is in "the onItemClick" methode.

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
private DBHelper mDbHelper = null;
private DreamDetails dreamDetails;
private ListView mListView;
private DrawerLayout drawerLayout;
private Toolbar mToolbar;
private Dao<DreamDetails, Integer> dreamDetailsDao;
private List<DreamDetails> dreamList;
private int selectedRecordPosition = -1;

protected void onCreate(Bundle savedInstanceState) {
mListView = (ListView) findViewById(R.id.listViewAllDreams);
try {
//Getting all Data from DB
dreamDetailsDao = getHelper().getDreamDetailsesDao();
dreamList = dreamDetailsDao.queryForAll();

// Set the header of the ListView
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view = inflater.inflate(R.layout.list_view, mListView, false);

// my own adapter!
mListView.setAdapter(new AdapterArrayDream(this,R.layout.list_view,dreamList,dreamDetailsDao));

} catch (SQLException e) {
FloatingActionButton myFab = (FloatingActionButton)findViewById(R.id.fab);
myFab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, NewDream.class);

public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if(i > 0)
selectedRecordPosition = i - 1;
// final Intent intent = new Intent(this, ViewDream.class);
Log.i("TAAAAAAG", "onClick " + adapterView.getItemAtPosition(selectedRecordPosition));
// intent.putExtra("D", String.valueOf(adapterView.getItemAtPosition(selectedRecordPosition)));
// startActivity(intent);
private void initNavigationView() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawlerLayout);
private void initToolbar() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return false;
// mToolbar.inflateMenu(R.menu.menu);

// This is how, DatabaseHelper can be initialized for future use

public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_list_dreams, menu);
return true;

private DBHelper getHelper() {
if (mDbHelper == null) {
mDbHelper = OpenHelperManager.getHelper(this, DBHelper.class);
return mDbHelper;



To create a query which looks up an account by name and password you would do the following:

QueryBuilder<Account, String> qb = accountDao.queryBuilder();
     Where where = qb.where();
     // the name field must be equal to "foo"
     where.eq(Account.NAME_FIELD_NAME, "foo");
     // and
     // the password field must be equal to "_secret"
     where.eq(Account.PASSWORD_FIELD_NAME, "_secret");
     PreparedQuery<Account, String> preparedQuery = qb.prepareQuery();