I have a doubt. When making an APP of phrases, I included when I clicked on a certain sentence an AlertDialog that has a checkbox, I would like to store all items that are checked with checkbox and play in a new activity that will be called a favorite and will be accessed from Button, but I do not know how to do it.
The code for my AlertDiagol and CheckBox is here:
// EVENTO DE CLIQUE
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
// CHECK BOX
View checkBoxView = View.inflate(FraseAutorFrase.this, R.layout.checkbox, null);
CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkbox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Save to shared preferences
}
});
checkBox.setText("Marcar como Favorito?");
// ALERT DIALOG
final String items = "Favorito";
final ArrayList seletedItems=new ArrayList();
//atributo da classe.
//Cria o gerador do AlertDialog
AlertDialog.Builder builder = new AlertDialog.Builder(FraseAutorFrase.this);
builder.setTitle("O que deseja fazer?");//define o titulo
builder.setMessage("Digite aqui sua mensagem!");//define a mensagem
builder.setView(checkBoxView);
//define um botão como positivo
builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
//define um botão como compartilhar
builder.setPositiveButton("Compartilhar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(FraseAutorFrase.this, "Você clicou no botão Compartilhar", Toast.LENGTH_SHORT).show();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, frasesR[position] );
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
});
alerta = builder.create();//cria o AlertDialog
alerta.show();//Exibe
}
});
Thank You!!!
Aucun commentaire:
Enregistrer un commentaire