0

I'm trying to display spinners values in popup box when button clicks. But the spinner values are not showing in popup window. This is the code in Attach Activity - Button click event:

btnimage.setOnClickListener(v->{
            View view = LayoutInflater.from(Attach.this).inflate(R.layout.activity_attach_form,null);
            AlertDialog.Builder builder = new AlertDialog.Builder(Attach.this);
            builder.setView(view);
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        });

In My attach form activity, am trying to show the spinner values.

Spinner spindoc;
String[] doc = {"select", "doc1", "doc2", "doc3"};
spindoc = findViewById(R.id.spindoc);
            spindoc.setOnItemSelectedListener(this);
            ArrayAdapter adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_item,doc);
            adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spindoc.setAdapter(adapter1);

Respective XML files:

<Spinner
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/spindoc"
            android:layout_marginTop="-20dp"
            android:textColor="#000000"
            android:layout_weight="1"
            />


Please let me know if I missed any syntax, while displaying spinners in popup. Because in normal view, the above code is working fine...

Venkatesh
  • 9
  • 4
  • see this doc brother [link] [https://material.io/components/menus/android#dropdown-menus] – D_K Nov 25 '21 at 11:28
  • ok refer this link surely help you : https://stackoverflow.com/a/6288030/12543430 – D_K Nov 25 '21 at 11:47
  • can u upload your code to github, so i can test it in my device also. – D_K Nov 26 '21 at 04:11
  • Thanks...I have shared google drive link - https://drive.google.com/file/d/1ONYMCMNtixweHwkI8vB2uBrjhcIb4eWG/view?usp=sharing – Venkatesh Nov 26 '21 at 04:43
  • brother can u please share .zip file,because i am unable to extract this rar file – D_K Nov 26 '21 at 05:15
  • https://drive.google.com/file/d/1B-RL74S04_GgdWXSd7CFs1PASGkYKvqU/view?usp=sharing - in this I have write coding in Attach and AttachForm.java files.. – Venkatesh Nov 26 '21 at 05:21
  • Any luck....@D_K...waiting for your reply.. – Venkatesh Nov 26 '21 at 08:22
  • try using android:spinnerMode="dialog" in spinner tag – D_K Nov 26 '21 at 09:56
  • Yes I already tried that...both dialog and dropdown... – Venkatesh Nov 26 '21 at 10:26
  • remove this adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); line and try to run see what will happen and let me know – D_K Nov 26 '21 at 10:30
  • I tried removing the same..but still no values display in spinner. – Venkatesh Nov 26 '21 at 11:03
  • can u share a video if possible. add this spinnerMode="dialog" and remove that line I told u before and run and share the video brother. – D_K Nov 26 '21 at 12:47
  • `` and commented the line `ArrayAdapteradapter = new ArrayAdapter(AttachForm.this, android.R.layout.simple_spinner_dropdown_item,doc); //adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spindoc.setAdapter(adapter);` – Venkatesh Nov 26 '21 at 13:01

0 Answers0