开发者

User Input causes form to appear

I want to have EditText object appear when a the User chooses "Combination" on a Spinner, How would I do this?

Here is what I have been trying:

     ground = (Spinner) findViewById(R.id.ground);
    ArrayAdapter<CharSequence> groundAdapter = ArrayAdapter.createFromResource(
            this, R.array.ground_array, android.R.layout.simple_spinner_item);
    groundAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    ground.setAdapter(groundAdapter);
    ground.setOnItemSelectedListener(new GroundListener());
    if(ground.getSelectedItem().toString().equalsIgnoreCase("Combination"))
    {
        combo.set开发者_如何转开发Visibility(0);
    }

the EditText object combo is set in xml file as android:visibility="gone"

GroundListener Code is

     public class GroundListener implements OnItemSelectedListener {

            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                String selected = parent.getItemAtPosition(pos).toString();
            }

            public void onNothingSelected(AdapterView parent)
            {
                // Do nothing.
            }
        }


What is a GroundListener ?

Shouldn't you be using an AdapterView.OnItemSelectedListener with its onItemSelected method ?

Beside, use setVisibility(View.VISIBLE) instead of 0 for readability.

EDIT:

I don't understand what you are doing with your code, your GroundListener is not plugged to anything and your test is outside of the listener.

Try :

ground.setOnItemSelectedListener(new OnItemSelectedListener() {

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

           if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Combination"))
            {
              combo.setVisibility(View.VISIBLE);
            }
        }

        public void onNothingSelected(AdapterView parent)
        {
            // Do nothing.
        }
    });

Check if that works and then bring back the code in your GroundListener to see if it works. You might have a problem though with the fact that the GroundListener might not know what is combo. But you'll work that out.

Edit:

Syntax Correction

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜