android中的edittext微调器

android中的edittext微调器,android,android-spinner,Android,Android Spinner,嗨,在我的应用程序中,我正在设计一个弹出式注册表。在那个类字段中,我想显示我使用微调器的那个类的下拉菜单,但那个类是单独的字段 我不想在单独的领域,我想在我想要的类的地方,我想要下拉菜单可以请告诉我我做错了什么 popuRegistration.java: public class PopupRegistration extends Activity implements OnItemSelectedListener { private String[] state =

嗨,在我的应用程序中,我正在设计一个弹出式注册表。在那个类字段中,我想显示我使用微调器的那个类的下拉菜单,但那个类是单独的字段 我不想在单独的领域,我想在我想要的类的地方,我想要下拉菜单可以请告诉我我做错了什么

popuRegistration.java:

    public class PopupRegistration extends Activity implements OnItemSelectedListener 
   {
    private String[] state = { "1", "2", "3",
            "4", "5", "6", "7",
            "8", "9"};

    public String log;
    public DatabaseHandlers db;

    GSfeedback cn;

    EditText etName,etClass,etrollno,etparentname,etphno; 
    Button btnregister;

    Spinner spinnerOsversions;
    EditText selVersion;
    TextView textView;
    String PHONE_REGEX;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popup_registration);
        System.out.println(state.length);
        db = new DatabaseHandlers(this);

        etName=(EditText)findViewById(R.id.etName); 
        selVersion=(EditText)findViewById(R.id.selVersion);
        etrollno=(EditText)findViewById(R.id.etrollno);
        etparentname=(EditText)findViewById(R.id.etparentname);
        etphno=(EditText)findViewById(R.id.etphno);

        btnregister=(Button)findViewById(R.id.registerbutton);

        PHONE_REGEX = "[0-9]+";
        spinnerOsversions = (Spinner) findViewById(R.id.osversions);
        ArrayAdapter<String> adapter_state = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, state);
        adapter_state
                .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnerOsversions.setAdapter(adapter_state);
        spinnerOsversions.setOnItemSelectedListener(this);


        btnregister.setOnClickListener(new View.OnClickListener() 
        {
        public void onClick(View v) {
             if(!validate()) {
                //Toast.makeText(getApplicationContext(), "Not Valid", Toast.LENGTH_SHORT).show();
             } else {
             if(!validates()) {
                    // Toast.makeText(getApplicationContext(), "Not valid", Toast.LENGTH_SHORT).show(); 
                 } else {
                     //Toast.makeText(getApplicationContext(), "valid", Toast.LENGTH_SHORT).show();
                     String studentname=etName.getText().toString(); 
                     String classid=etClass.getText().toString();
                     String rollno=etrollno.getText().toString(); 
                    String parentname=etparentname.getText().toString();
                     String phno=etphno.getText().toString();

                     // Save the Data in Database
                     db.addGSfeedback(new GSfeedback(studentname,classid,rollno,parentname,phno));

                     Toast.makeText(getApplicationContext(), "Thanks for Registration, Welcome to Lilttle Flowers Public School Android App.", Toast.LENGTH_LONG).show();

                     etName.setText("");
                     etClass.setText("");
                     etrollno.setText("");
                     etparentname.setText("");
                     etphno.setText("");

                     finish();
                     Intent nextScreen = new Intent(getApplicationContext(), Splashscreen.class);
                     startActivity(nextScreen);

                 }
             }
        }

        });
        }


        public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
            spinnerOsversions.setSelection(position);
            String selState = (String) spinnerOsversions.getSelectedItem();
            selVersion.setText("Selected Android OS:" + selState);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }




        private boolean validate(){
        if(etName.length() == 0 || etClass.length() == 0 || etrollno.length() == 0 || etphno.length() == 0 || etparentname.length() == 0){
            Toast.makeText(getApplicationContext(), "pls fill the empty fields", Toast.LENGTH_SHORT).show();
            return false;
        } if(etName.length() > 30 && etparentname.length() > 30){
            //Toast.makeText(getApplicationContext(), "pls enter less the 25 characher", Toast.LENGTH_SHORT).show();
            etName.setError("pls enter less the 30 charachter");                
            return true;

        } else if(etphno.length() < 6 || etphno.length() > 13){
            //etNumber.setError("Not Valid Phone Number");
            Toast.makeText(getApplicationContext(), "Enter valid Phone Number", Toast.LENGTH_SHORT).show();
            return false;
        } else {
            return true;
        }
    }

        private boolean validates(){
        if(etphno.getText().toString().trim().matches(PHONE_REGEX)) {
            return true;
        } else {     
            Toast.makeText(getApplicationContext(), "Enter Valid Phone Number", Toast.LENGTH_SHORT).show();   
             return false;              
        }
    }
    }
popuRegistration.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_vertical" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >       

    <EditText
        android:id="@+id/etName"
        android:hint="Student Name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"> 
        <requestFocus />       
    </EditText>

     <Spinner
        android:id="@+id/osversions"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" />
    <EditText
        android:id="@+id/selVersion" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
          android:layout_below="@+id/osversions"
        android:hint="Class"/>
    <EditText
        android:id="@+id/etrollno"
        android:hint="Roll Number"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"> 
        <requestFocus />       
    </EditText>

     <EditText
        android:id="@+id/etparentname"
        android:hint="Parent Name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"> 
        <requestFocus />       
    </EditText>
    <EditText
        android:id="@+id/etphno" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Phone Number" />

    <Button
        android:id="@+id/registerbutton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="REGISTER"
        android:layout_marginBottom="60dp" />

    </LinearLayout>
    </ScrollView>

   </LinearLayout>

谢谢。

如果您想要注册的弹出窗口,您可以使用一个而不是微调器。您可以使用微调器从列表中选择值,而不是显示注册弹出窗口

PopupWindow有一个方法showAsDropDown,它会在锚点下显示它,使它看起来像一个下拉列表

希望这有帮助

例如:

    // inflate your layout where you might add some edit texts for login and password
    View popupWindowView = getActivity().getLayoutInflater().inflate(R.layout.your_layout, null, false);
    mPw = new PopupWindow(
            popupWindowView,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            true);

    mPw.setOutsideTouchable(true);
    mPw.showAsDropDown(anchor, xOffset, yOffset); 

你能告诉我怎么用它吗example@user3437313我加了一个例子