mardi 30 juin 2015

Getting GetId() to work on a LinkedList()

Further to my question "Extracting multiple data items from LinkedList() element" which now works fine on the demo "Book" app thanks to quocnhat7, I've come across the next issue setting up the onItemClick. In this case, the getId() method, which throws "error: cannot find symbol method getId()" on building the app.

    // get all books
    List<Book> list = db.getAllBooks();
    List<String> listTitle = new ArrayList<String>();

    for (int i = 0; i < list.size(); i++) {
        listTitle.add(i, list.get(i).getTitle());
                }

    myAdapter = new ArrayAdapter(this, R.layout.row_layout, R.id.listText, listTitle);
    getListView().setOnItemClickListener(this);
    setListAdapter(myAdapter);
}

@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
    // start BookActivity with extras the book id
    Intent intent = new Intent(this, BookActivity.class);
    // Don't seem to be able to access Book.java for getId function
    intent.putExtra("book", list.get(arg2).getId());
    startActivityForResult(intent, 1);
}

Aucun commentaire:

Enregistrer un commentaire