0
Hello, i have an Activity class, which shows a layout with a list of items, which when clicking on each item, would show a new layout (books2), with a viewFlipper, however, each item in the list should show a set of different images, only it only shows the same set of images, which is in the Book itself. Where am I going wrong?
List class:
public class Activity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Arrays de imagens:
final int livro1[] = {R.drawable.desenho1, R.drawable.desenho2, R.drawable.desenho3};
int livro2[]={R.drawable.desenho2,R.drawable.desenho1,R.drawable.desenho3};
final ArrayList<Itens> livros = new ArrayList<Itens>();
livros.add(new Itens("Livro 1", "Autor 1",livro1));
livros.add(new Itens("Livro 2", "Autor 2",livro2));
livros.add(new Itens("Livro 3", "Autor 3",livro1));
MeuAdapter array = new MeuAdapter (this,livros);
ListView lista = (ListView)findViewById(R.id.item);
lista.setAdapter(array);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent intent = new Intent(Livros.this, Livros2.class);
startActivity(intent);}
});
}
}
And the class that should be used to open the array of books is as follows:
public class Livros2 extends AppCompatActivity {
private Button anterior,proxima;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_livros2);
int[]imagens ={R.drawable.desenho2,R.drawable.images,R.drawable.desenho3};
final ViewFlipper trocarImagens = (ViewFlipper)findViewById(R.id.flip);
for (int i = 0; i<imagens.length; i++){
ImageView nova = new ImageView(this);
nova.setImageResource(imagens[i]);
trocarImagens.addView(nova);//}
anterior = findViewById(R.id.voltar);
anterior.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
trocarImagens.showPrevious();
}
});
proxima = findViewById(R.id.avançar);
proxima.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
trocarImagens.showNext();
}
});
}}}
Isabela, the language tag is also required, and because it’s android, I added the java tag, which is the language you’re working on.
– user28595
Ah, ok! Thank you!!
– Isabela Andrade
No. I made a mistake, I’m sorry. Now I’m done!
– Isabela Andrade