Click here to Skip to main content
15,070,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Not working in spinner but working in oncreate method

I have two array one is blanked & another one which having three images in it when i'm assigning it to an blanked array in spinner on selected it shows error but if i write in oncreate method it will show 3 images.



Java
public Integer[] arr = {R.drawable.p231, R.drawable.p231, R.drawable.p231};
        public Integer[] arr1 = {};
        String item;
        Integer[] imageIDs =  {};

    Bitmap bp;
    Gallery gallery;
    int temp;
    RelativeLayout can;
    ImageView capturedImage;
    StickerImageView iv_sticker;
    private Toolbar toolbar;
    Spinner spinner;
    int flag=0;
    CheckBox chk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_camera);
//        chk = (CheckBox) findViewById(R.id.chk);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        capturedImage = (ImageView) findViewById(R.id.capturedImage);
        spinner = (Spinner) findViewById(R.id.Cam_spinner);


        if (toolbar != null) {
            setSupportActionBar(toolbar);
            getSupportActionBar().setDisplayShowTitleEnabled(false);

        }

        arr1 = arr;
        imageIDs = arr1;



        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.Gates, android.R.layout.simple_spinner_item);

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spinner.setAdapter(adapter);


        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

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


                item = spinner.getSelectedItem().toString();

            if(item.equals("Door Gate"))
            {
                          //    arr1 = arr;
 not working*            //  imageIDs = arr1;
     Toast.makeText(getApplicationContext(),"door"+temp,Toast.LENGTH_LONG).show();
            }
              //  Toast.makeText(getApplicationContext(),""+item,Toast.LENGTH_LONG).show();
                 //item = position;


                }



            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }

        });

        Intent intent = getIntent();
        bp = (Bitmap) intent.getParcelableExtra("data");
        capturedImage.setImageBitmap(bp);


        gallery = (Gallery) findViewById(R.id.gallery1);
        gallery.setAdapter(new ImageAdapter(this));
        gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(getBaseContext(), "pic" + (position + 1) + " selected",
                        Toast.LENGTH_SHORT).show();


                can = (RelativeLayout) findViewById(R.id.canvasView);
                iv_sticker = new StickerImageView(CameraActivity.this);

                iv_sticker.setImageResource(imageIDs[position]);
                can.addView(iv_sticker);//Working sticker code

                  if (R.id.can == 0) {
                    flag = 0;
                } else {
                    flag++;
                }
              }
        });
    }


What I have tried:

I have tried to assign image array to blank array & many more things.
Posted
Updated 8-Jul-16 23:44pm
v3
Comments
Richard MacCutchan 9-Jul-16 5:45am
   
What is the error, and where does it occur?
priyanshbhaliya 12-Jul-16 0:56am
   
can you give logcat info of error???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900