Error while placing a spinner inside Activity Group

后端 未结 4 1902
情话喂你
情话喂你 2020-12-09 00:05

I have an activity group containing 3 activities. When a button is pressed, I enter into this activity group and show the 1st activity. From the 1st activity I can goto 2nd

相关标签:
4条回答
  • 2020-12-09 00:18

    can you add spiner.setDropDownViewResource()?and in your initialization ,you use context called this or getApplicationContext(),for example AlertDialog.Builder(xxx.this) => AlertDialog.Builder(this.getParent())

    0 讨论(0)
  • 2020-12-09 00:23

    The error was with the setContentView. I had given

    setContentView(R.layout.mylayout);
    

    Instead of that we should give,

    View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.mylayout, null);
    this.setContentView(viewToLoad);  
    

    And the spinner code is:

    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.request_options, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
        spinner.setAdapter(adapter);
    
    0 讨论(0)
  • 2020-12-09 00:27

    this may solve your problem this.getParent() i used it in my code many times. it worked f9.

    0 讨论(0)
  • 2020-12-09 00:37

    Mathew his method works:

    View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.mylayout, null);
    this.setContentView(viewToLoad);  
    

    i folowed this method to and then my application crashes on button click. To solve this remove the onClick method out the xml file. Go to the java class and add button.setOnClickListener!

    0 讨论(0)
提交回复
热议问题