2016-09-21 18 views
0

私はスピナーを使用しようとしています。私はスピナーと一緒に他の意見を持っています。他のすべてのビューが表示され、スピナー以外は正常に動作します。実行時にスピナーはまったく表示されません。ただし、デザインモードでは表示されますが、実行時には表示されません。アプリケーションの実行時にスピナーが表示されない

私のXMLは以下の通りです:

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/background" 
    tools:context="com.example.kc.sample.HomePage"> 

    <ScrollView 
     android:id="@+id/scrollView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:fillViewport="true"> 

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

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="30dp"> 
       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:inputType="textCapSentences" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:textColor="#274A72" 
        android:id="@+id/editRegisterName" 
        android:hint="@string/Name" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="64"/> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerDOB" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:inputType="textCapSentences" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:focusableInTouchMode="false" 
        android:textColor="#274A72" 
        android:id="@+id/editRegisterDOB" 
        android:hint="@string/DOB" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="64"/> 
      </android.support.design.widget.TextInputLayout> 

      <TableLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:stretchColumns="*" 
       android:shrinkColumns="*"> 
       <TableRow> 
        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_GenderMale" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioGenderMale" 
          android:text="@string/Male" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkMaleMethod" 
         /> 
        </android.support.design.widget.TextInputLayout> 

        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_GenderFemale" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:layout_marginRight="10dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioGenderFemale" 
          android:text="@string/Female" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkFemaleMethod" 
         /> 
        </android.support.design.widget.TextInputLayout> 
       </TableRow> 
      </TableLayout> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerEmail" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="40dp" 
        android:inputType="textCapSentences" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:textColor="#274A72" 
        android:id="@+id/editRegisterEmail" 
        android:hint="@string/email" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="64"/> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       style="@style/fontStyle" 
       android:id="@+id/input_layout_registerMobile" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 
       <EditText 
        android:layout_width="match_parent" 
        android:inputType="number" 
        android:layout_height="40dp" 
        android:id="@+id/editRegisterPhone" 
        android:textSize="15dp" 
        android:paddingStart="@dimen/activity_horizontal_margin" 
        android:textColor="#274A72" 
        android:hint="@string/Phone" 
        android:singleLine="true" 
        android:background="@drawable/edit_text_border" 
        android:lines="1" 
        android:maxLength="10"/> 
      </android.support.design.widget.TextInputLayout> 

      <TableLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:stretchColumns="*" 
       android:shrinkColumns="*"> 
       <TableRow> 
        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_statusSingle" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioStatusSingle" 
          android:text="@string/Single" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkStatusSingleMethod" 
          /> 
        </android.support.design.widget.TextInputLayout> 

        <android.support.design.widget.TextInputLayout 
         style="@style/fontStyle" 
         android:id="@+id/input_layout_statusMarried" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:layout_weight="1"> 
         <RadioButton 
          android:layout_width="match_parent" 
          android:layout_height="40dp" 
          android:layout_marginRight="10dp" 
          android:textSize="15dp" 
          android:paddingStart="@dimen/activity_horizontal_margin" 
          android:textColor="#274A72" 
          android:id="@+id/radioStatusMarried" 
          android:text="@string/Married" 
          android:background="@drawable/edit_text_border" 
          android:onClick="checkStatusMarriedMethod" 
          /> 
        </android.support.design.widget.TextInputLayout> 
       </TableRow> 
      </TableLayout> 

      <Spinner 
       android:id="@+id/spinner" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:prompt="@string/spinner_title" 
       /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/txtErrorMessage" 
       android:textAlignment="center" 
       android:textSize="15dp" 
       android:textColor="#ff0000"/> 

     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

マイ対応するJavaコードは以下の通りです:

public class HomePage extends AppCompatActivity implements View.OnClickListener, OnItemSelectedListener { 

    private EditText editName, editDateofBirth, editMail, editMobileNumber, editDate; 
    private RadioButton radioMale, radioFemale, radioStatusSingle, radioStatusMarried; 
    private Button btnPrevious, btnNext; 
    Dialog result; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_home_page); 

     //Few other view declaration here 

     Spinner spinner = (Spinner) findViewById(R.id.spinner); 
     spinner.setOnItemSelectedListener(this); 

     List<String> list = new ArrayList<>(); 
     list.add("One"); 
     list.add("Two"); 
     list.add("Three"); 
     list.add("Four"); 

     ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);   dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
     spinner.setAdapter(dataAdapter); 

    } 
@Override 
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { 
     String item = adapterView.getItemAtPosition(i).toString(); 
     Toast.makeText(adapterView.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onNothingSelected(AdapterView<?> adapterView) { 

    } 

分離した個々のプロジェクトとして書かれている場合、同じスピナーのコードが正常に動作し、期待されるものの含むものとして上記のコードスニペットでは、実行時にスピナーを表示しません。誰も私にそれを動作させる方法を導くことができますか?事前のおかげで

答えて

0

Fillプロパティは廃止され、使用:

<Spinner 
    android:id="@+id/spinner" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/spinner_title" 
      /> 
関連する問題