0
I receive in an Edittext a date and I need that when pressing the renewal button this date is increased 1 day.
package br.edu.unp.bibliotecavirtual.view;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.ArrayList;
import br.edu.unp.bibliotecavirtual.R;
import br.edu.unp.bibliotecavirtual.config.CustomAdapterLivro;
import br.edu.unp.bibliotecavirtual.config.DatabaseHelper;
import br.edu.unp.bibliotecavirtual.model.RenovacaoModelo;
public class ListarEmprestimosActivity extends AppCompatActivity {
private EditText empTitulo, empDataemp, empDatadevol; //,
etRegistroLivro;
private Button btnRenovado, btnDevolvido;
private RenovacaoModelo renovacaoModelo;
//private View view;
// private ListView listView;
private ArrayList<RenovacaoModelo> renovacaoModeloArrayList;
private CustomAdapterLivro customAdapterlivro;
private DatabaseHelper databaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_renovates_give_back);
Intent intent = getIntent();
renovacaoModelo = (RenovacaoModelo)
intent.getSerializableExtra("user");
databaseHelper = new DatabaseHelper(this);
//RESGATA VALORES PARA OS TEXTVIEW VINDOS DOS GETTER E SETTERS e dos ArrayLists
//displays in textview
empTitulo = findViewById(R.id.empTitulo);
empDataemp = findViewById(R.id.empDataemp);
empDatadevol = findViewById(R.id.empDatadevol);
empTitulo.setText(renovacaoModelo.getTitulo());
empDataemp.setText(renovacaoModelo.getDataemp());
empDatadevol.setText(renovacaoModelo.getDatadevol());
// BOTOES DE AÇÃO DO FORMULÁRIO
btnRenovado = findViewById(R.id.btnRenovado);
btnDevolvido = findViewById(R.id.btnDevolvido);
// função dos botoes renovar entregar
btnRenovado.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//, etRegistro.getText().toString()
databaseHelper.renovaLivro(renovacaoModelo.getId(),
empTitulo.getText().toString(),
empDataemp.getText().toString(), empDatadevol.getText().toString());// ,
etRegistroLivro.getText().toString());
Toast.makeText(ListarEmprestimosActivity.this, "Livro
Renovado com Sucesso!", Toast.LENGTH_SHORT).show();
// MainActivity = tela principal
Intent intent = new Intent(ListarEmprestimosActivity.this,
MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
btnDevolvido.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//renovacaoModelo
databaseHelper.devolverLivro(renovacaoModelo.getId());
Toast.makeText(ListarEmprestimosActivity.this, "Livro
Devolvido com Sucesso!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(ListarEmprestimosActivity.this,
MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
}
the class with the function that will update the database:
public int renovaLivro(int id, String titulo, String dataempre, String
datadevol) {
SQLiteDatabase db = this.getWritableDatabase();
//Criando valores do content
ContentValues values = new ContentValues();
values.put(KEY_EMP_ID, id);
values.put(KEY_TITULOEMPRE, titulo);
values.put(KEY_DATAATUAL, dataempre);
values.put(KEY_DATADEVOLUCAO, datadevol); // adiciona mais 10
dias na data final
//---> //
return db.update(TABLE_EMPRESTIMO, values, KEY_EMP_ID + " = ?",
new String[]{String.valueOf(id)});
}
// fim função emprestimo
This part where I get my date released in Edittext was not very clear to me, could explain?
– user3873165
Pronto @user3873165, I added an edit to my reply to make it clear how to do this
– Ivan Silva
right, now I understand better, I’ll try to adapt, but I see that it would take a new Edittext to manipulate the data transparently and deliver the final date only in the bank and also in a messenger style Oast, because if the user does nothing there will be no transformations in these elements.
– user3873165
If I understand correctly, you don’t need another
EditText
. Just use what you already have– Ivan Silva
but I will not load this new date into it, only after the new database query, however I want to show in a Toast style message. 'Toast.makeText(Listremprestimosactivity.this, "Successfully Renewed Book! The new renewed date will be: "date.gettext().toString(), Toast.LENGTH_SHORT). show();'
– user3873165
I edited again so it’s possible to show the date as
String
– Ivan Silva
By performing some tests I was able to print the expected value in an editText, but after successive tests it gave an error: Attempt to invoke virtual method 'long java.util.Date.getTime()' on a null Object Reference This is due to Date = null; when it circles the parse with Try catch?
– user3873165
You should probably enter because this behavior is happening
– Ivan Silva