J'espère que je n'ai pas foiré! Mais j'ai créé et app et l'ai à peu près fini mais quand j'appuie sur le bouton de retour il ferme l'application. Je me rends maintenant compte que je change seulement la vue sur mon activité principale au lieu de lancer des activités séparées en utilisant l'intention. l'application a 3 boutons pour charger 3 différentes "vues" (facile, moyen, dur) chacune est remplie d'un tableau d'images. Je vais poster du code mais je ne sais pas ce qui est nécessaire. devrais-je remplacer le bouton de retour pour revenir à la vue MainActivity? pas sûr de la meilleure façon de résoudre ce problème. mercibouton arrière avec adaptateur d'image (baseadapter)
public void onClick(View v) {
switch (v.getId()){
case R.id.btnEasy:
creatArray();
btnEasy.setVisibility(View.INVISIBLE); //hides button on the second activity
btnMed.setVisibility(View.INVISIBLE);
btnHard.setVisibility(View.INVISIBLE);
btnHome.setVisibility(View.VISIBLE);
btnReset.setVisibility(View.VISIBLE);
btnFloat.setVisibility(View.INVISIBLE);
grid=(GridView)findViewById(R.id.grid); //grid is @id of grid in MainActivity
grid.setVisibility(View.VISIBLE);
EasyGridAdapter adapter = new EasyGridAdapter(MainActivity.this, randomPics, overlay); //have to add all images (arrays here) references arrays above
grid.setAdapter(adapter);
break;
public class EasyGridAdapter extends BaseAdapter {
private int[] easyPics;
private int[] overlayPic; //used for overlay ...this is just created here
Context myContext;
String pos0,pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8; //for scoring game
public class Holder
{
RelativeLayout rlParent; //main layout (custom_easy.xml)
ImageView iv; //for images (grid) main ones
ImageView ol; //for overlay
}
public EasyGridAdapter(Context myContext, int easyPics[], int overlayPic[]){
//sets gridadapter to use pics , if had text under pic would need to add after int[] pics
// name EasyGridAdapter is name ot the java class
this.myContext = myContext;
this.easyPics = easyPics;
this.overlayPic = overlayPic;
}
@Override
public int getCount() {
return easyPics.length;
}
@Override
public Object getItem(int position) {
return easyPics[position]; //worked with just easypics
// return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView (final int position, View convertView, ViewGroup parent) {
View grid = convertView; //grid (not sure if this is the same) is @id of grid on activity main
final Holder holder=new Holder();
if (convertView == null){
LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); //think inflates above public EasyGridAdapter
grid = inflater.inflate(R.layout.custom_easy, null);
}
//main view (i think inializing veiw)
holder.rlParent = (RelativeLayout) grid.findViewById(R.id.customParent); //customeParent @id set on custom_easy.xml
holder.iv = (ImageView) grid.findViewById(R.id.easyPics); //EasyPics is android id name of imageviewer in custom easy xml
holder.ol = (ImageView) grid.findViewById(R.id.overlayPic);
holder.iv.setImageResource(easyPics[position]); //easypics is the interger from above
holder.rlParent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (position==0)
{
REMOVED TO SAVE SPACE...
holder.ol.setVisibility(View.VISIBLE);
}
});
return grid; //returns grid which is name of grid on activity_main.xml (with all stuff in it)
}
}