Estou tentando fazer um aplicativo de agenda telefonica. Ao adicionar o contato no sqlite o programa troca a activity e não exibe os dados cadastrados. O código da Main é:
package com.example.agendatrabdois.UI;
import android.content.Intent;
import android.os.Bundle;
import com.example.agendatrabdois.DAO.Constants;
import com.example.agendatrabdois.DAO.DatabaseHelper;
import com.example.agendatrabdois.MODEL.Adapter;
import com.example.agendatrabdois.MODEL.Model;
import com.example.agendatrabdois.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ListView;
public class MainActivity extends AppCompatActivity {
RecyclerView lista;
FloatingActionButton fab;
DatabaseHelper databaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lista=findViewById(R.id.lista_recycler);
databaseHelper= new DatabaseHelper(this);
showRecord();
fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this,formularioContato.class));
}
});
}
private void showRecord()
{
Adapter adapter;
adapter= new Adapter(MainActivity.this, databaseHelper.getAllData());
lista.setAdapter(adapter);
///
}
@Override
protected void onResume() {
super.onResume();
showRecord();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}