jeudi 2 novembre 2017

Display a image in gridview based on if condition

Hi, so i have a gridview and i'm trying to set gridview's items image after a if statement in gridview's onItemClick... in below code i tried to explain my question in backslashs:

 GridView grid;
String[] web = {
        "test",
        "test",
        "test",
        "test",
        "test"

} ;
int[] imageId = {
        R.drawable.example,
        R.drawable.example,
        R.drawable.example,
        R.drawable.example,
        R.drawable.example
};



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.first_frag, container, false);

    CustomGrid adapter = new CustomGrid(getActivity(), web, imageId);
    grid=(GridView) v.findViewById(R.id.grid);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {


        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            switch(position){

                case 0:
                    if (level_1_isdone == true){
                        //set a image
                       }
                    else {
                        //set some other image 
                       }

                case 1:
                case 2:
                case 3:
                case 4:
            }
        }
    });

    return v;
}

how can i do that?

Aucun commentaire:

Enregistrer un commentaire