Boa noite. Fiz conforme vídeo aula porem não abre o browser.
package com.example.marce.agenda;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import com.example.marce.agenda.dao.AlunoDAO;
import java.util.List;
public class ListaAlunosActivity extends AppCompatActivity {
private ListView listaAlunos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_alunos);
listaAlunos = (ListView) findViewById(R.id.listaAlunos);
listaAlunos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> lista, View item, int position, long id) {
Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(position);
Intent intent = new Intent(ListaAlunosActivity.this, FormularioActivity.class);
intent.putExtra("aluno",aluno);
startActivity(intent);
Toast.makeText(ListaAlunosActivity.this, "Aluno = " + aluno.getNome(), Toast.LENGTH_SHORT).show();
}
});
listaAlunos.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(ListaAlunosActivity.this, "Clique longo", Toast.LENGTH_SHORT).show();
//se colocar true ele executa tb o onCreateContextMenu
return false;
}
});
Button novoAluno = (Button) findViewById(R.id.novo_aluno);
novoAluno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ListaAlunosActivity.this, FormularioActivity.class);
startActivity(intent);
}
});
registerForContextMenu(listaAlunos);
}
@Override
protected void onResume() {
super.onResume();
carregaLista();
}
private void carregaLista() {
AlunoDAO dao = new AlunoDAO(this);
List<Aluno> alunos = dao.buscaAlunos();
dao.close();
ArrayAdapter<Aluno> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, alunos);
listaAlunos.setAdapter(adapter);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, final ContextMenu.ContextMenuInfo menuInfo) {
MenuItem itemSite = menu.add("Visitar Site");
Intent intentSite = new Intent(Intent.ACTION_VIEW);
intentSite.setData(Uri.parse("https://www.google.com.br"));
intentSite.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
itemSite.setIntent(intentSite);
MenuItem deletar = menu.add("Deletar");
deletar.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(info.position);
AlunoDAO dao = new AlunoDAO(ListaAlunosActivity.this);
dao.deleta(aluno);
dao.close();
carregaLista();
Toast.makeText(ListaAlunosActivity.this, "Item clicado = " + aluno.getNome(), Toast.LENGTH_SHORT).show();
return false;
}
});
}
}