开发者

My Android spinner works without an ArrayAdapter...why?

Will I come to the heaven or to the hell? As I had to populate 5 spinners, I tried very compact code. I didn´t understand why I should use a ArrayAdapter, so I simply dropped it out, in spite all tutorials use it. I was surpraised, as it worked. The code is showing only one spinner:

 Spinner s2_height = (Spinner)findViewById(R.id.s2_height);
    s2_height.setOnItemSelectedListener(new OnItemSelectedListener() {  //Register a callback to be invoked when an item in this AdapterView has been selected.
        public void onItemSelected(AdapterView<?> arg0, View arg1,  //Callback method to be invoked when an item in this view has been selected
                int arg2, long arg3) {
            myCalc();}
        public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

        }
});

This is the location in my .java, where I d开发者_JAVA技巧ropped out the ArrayAdapter section, normaly being in tutorials recomanded as:

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
            this, R.array.Height_array_id, android.R.layout.simple_spinner_item);
   adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   s2_height.setAdapter(adapter);

And surprisingly, it worked, I placed a method myCalc which displays the ItemPosition on all 5 spinners correctly. Now I am afraid that I´ll get any drawback at another place, may be at changing colours, or text heights. Has somebody the same problem?


Will I come to the heaven or to the hell?

That would be a question for your priest, minister, rabbi, etc. It is not a relevant question for StackOverflow.

I didn´t understand why I should use a ArrayAdapter, so I simply dropped it out

You do not have to use an ArrayAdapter, but you have to use some form of SpinnerAdapter to populate the Spinner via setAdapter(). Otherwise, the Spinner will be empty. If your Spinner is not empty, that means you called setAdapter() on it somewhere.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜