2014-05-06 55 views
0

嗨在我的應用程序我設計一個彈出註冊表單。在該類字段,我想顯示下拉菜單中的那一個我用微調,但那一個它採取單獨的字段
我不想在單獨的領域,我想代替班級我想下拉菜單可以請告訴我什麼我錯了。edittext微調在android

popupregistration.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;    
     } 
    } 
    } 

popupregistration.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> 

謝謝。

回答

0

如果您想要註冊的彈出窗口,您可以使用PopupWindow而不是Spinner。您將使用微調器從列表中選擇一個值,而不是顯示註冊彈出窗口。

而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); 
+0

u能告訴我怎麼用舉一些小例子 – user3437313

+0

@ user3437313我添加了一個例子 – andrei