0
I have here an arraylist that is shown in a listview, when I give long click a dialog is displayed there contains the favorite option that when it is selected the obeject is marked as true, as I do to display only the items marked in my Activityfavorites?
Mainactivity.class
public class MainActivity extends AppCompatActivity {
ListView lv;
MediaPlayer mp;
ArrayList<memes> item;
ArrayAdapter<memes> arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_main);
lv = findViewById(R.id.lv);
mp = new MediaPlayer();
item = new ArrayList<>();
//itens
item.add(new memes("Fique apertado sobre o meme para compartilhar", R.raw.sharebagui));
item.add(new memes("2 mil anos", R.raw.milanos));
item.add(new memes("Acelera jesus", R.raw.acelera_jesus));
item.add(new memes("Azideia", R.raw.asideia));
item.add(new memes("Acertou mizeravi", R.raw.mizeravi));
arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, item);
lv.setAdapter(arrayAdapter);
//play audio
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
playSong(position);
}
});
//PROGRESS
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, final int position, long l) {
//PROGRESS
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Olá, Marilene!");
builder.setItems(Nomes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0: // Delete
sendWhatsAppAudio(position);
break;
case 1: // Copy
item.get(position).setmIsFavourite(true);
break;
default:
break;
}
}
});
AlertDialog alertDialog = builder.create();
builder.show();
return true;
}
});
}
public void playSong(int songIndex) {
mp.reset();
mp = MediaPlayer.create(this, arrayAdapter.getItem(songIndex).getResId());
mp.start();
}
@Override
public void onDestroy() {
super.onDestroy();
mp.release();
}
}
memes.class
public class memes{
private String nome;
private int resID;
private Boolean mIsFavourite;
memes(String nome, int resID){
this.nome = nome;
this.resID = resID;
}
public String getNome(){
return nome;
}
int getResId(){
return resID;
}
@Override
public String toString(){
return nome;
}
public Boolean getmIsFavourite() {
return mIsFavourite;
}
public void setmIsFavourite(Boolean mIsFavouriteResource) {
this.mIsFavourite = mIsFavouriteResource;
}
}
Activityfavoritos.class
public class ActivityFavoritos {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_favoritos);
lv = findViewById(R.id.lvf);
if (list.get(position).getmIsFavourite()) {
//do want you want when its true
} else {
//do want your code when its false.
}
arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, item);
lv.setAdapter(arrayAdapter);
}
}
Your question is not very clear, could explain your problem better!
– Nayron Morais
@Nayronmorais I want to do a favorite scheme, for this in Mainactivity in this part
case 1:
 item.get(position).setmIsFavourite(true);
 break;
i select the items with true, and want to retrieve them in Activityfavorites only those marked as true, but n know how to do this. And if in the case of a miracle I managed to display the items in a listview on Activity favorites, I have another question, I will have to rewrite the mediaplayer on Activity favorites for them to play?– Welyson
You will not be able to do what you want the way you are doing, in which case, using the standard Adapters, you will have to create your own Adapter by extending Adapter. And within your Adapter implement the logic you want!
– Nayron Morais