• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android studio Sugar db

d2rights

Lurker
This is the code I have so far

public Button save;
public EditText etBook, etEdition, etAuthor,etAuthorl;
public String title;


etBook = (EditText) findViewById(R.id.etBook);
etEdition = (EditText) findViewById(R.id.etEdition);
etAuthor = (EditText) findViewById(R.id.etAuthorf);
etAuthorl = (EditText) findViewById(R.id.etAuthorl);
title = "updated title here";
Button save = (Button) findViewById(R.id.save);




save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {


String title = etBook.getText().toString();
String edition = etEdition.getText().toString();
String first = etAuthor.getText().toString();
String last = etAuthorl.getText().toString();

Author author = new Author(first, last);
author.save();

Book book = new Book(author, title, edition );
book.save();
}
});

Button Viewbooks = (Button)findViewById(R.id.viewbooks);

Viewbooks.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this, ViewAllBooks.class);
startActivity(intent);
}
});

Button Deleteallbooks = (Button)findViewById(R.id.btnDelete);

Deleteallbooks.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
List<Book> books = Book.listAll(Book.class);

Book.deleteAll(Book.class);
}ArrayAdapter<Book> adapter;

});
**This is working view code**

ArrayAdapter<Book> adapter;
ListView mListview;


mListview = (ListView)findViewById(R.id.listBooks);

List<Book> list = Book.listAll(Book.class);

adapter = new ArrayAdapter<Book>(ViewAllBooks.this,android.R.layout.simple_list_item_1,list);
mListview.setAdapter(adapter);

**This is the code I'm having trouble with**


Button UpdateBook = (Button)findViewById(R.id.btnUpdate);

UpdateBook.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {
Toast toast = Toast.makeText(MainActivity.this,"Work in progress",Toast.LENGTH_LONG);
toast.show();
Book book = Book.findById(Book.class, 1);
`book.title = "updated title here";
book.edition = "3rd edition";
book.save();`
}
});
`Button DeleteEntry = (Button)findViewById(R.id.btnDeleteEntity);`

DeleteEntry.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view) {

Toast toast = Toast.makeText(MainActivity.this,"Work in progress",Toast.LENGTH_LONG);
toast.show();
Book book = Book.findById(Book.class, 1);
`book.delete();`
}
});
 
Back
Top Bottom