Android Spinner不显示下拉菜单

时间:2018-09-04 10:46:25

标签: java android android-spinner

我正在尝试在 FrameLayout 中显示微调器,但未显示下拉菜单。我找不到问题。

  

XML

$client = new SoapClient("http://www.xyz.Services?Wsdl", array('soap_version'   => SOAP_1_2,'trace' => 1,'exceptions'=> false
    ));
    $wsa_namespace = 'http://www.w3.org/2005/08/addressing';
    $ACTION_ISSUE = 'http://www.xyx/getPassword';// Url With method name
    $NS_ADDR = 'http://www.w3.org/2005/08/addressing';
    $action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);

    $to = new SoapHeader($NS_ADDR, 'To', 'http://www.xyx.svc/Basic', false);
    $headerbody = array('Action' => $action,'To' => $to);
    $client->__setSoapHeaders($headerbody);


    //$fcs = $client->__getFunctions();
    //pre($client->__getLastRequest());
//pre($fcs);

$parameters=array('UserId'=>'12345678','MemberId'=>'123456','Password' => '123456','PassKey' => 'abcdef1234');
;
$result = $client->__soapCall('getPassword', array($parameters));//getPassword method name
print_r(htmlspecialchars($client->__getLastRequest()));// view your request in xml code

print_r($client->__getLastRequest());die; //Get Last Request

print_r($result);die; //print response
  

代码

 <FrameLayout
//design continue here
    <LinearLayout
            android:id="@+id/tab3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#5b89ff"
            android:orientation="vertical">
            <Spinner
                android:id="@+id/spinner"
                android:spinnerMode="dropdown"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
            />

        </LinearLayout>
    </FrameLayout>`
  

我的onCreate方法

final List<String> list=new ArrayList<>();

    list.add("jamshaid");
    list.add("jamshaid");
    list.add("jamshaid");
    list.add("jamshaid");
    list.add("jamshaid");

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

更新1

使用RelativeLayout代替FrameLayout抛出
    TabHost host; host = findViewById(R.id.tabHost); spinner= findViewById(R.id.spinner); progressDialog=new ProgressDialog(this); host.setup(); //Tab 1 TabHost.TabSpec spec = host.newTabSpec("News Feed"); spec.setContent(R.id.tab1); spec.setIndicator("News Feed"); host.addTab(spec);`

3 个答案:

答案 0 :(得分:0)

删除此行并检查,

arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //Comment this line
  

也尝试此更改:

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,
            android.R.layout.simple_spinner_dropdown_item, list); //Changed layout resource id

答案 1 :(得分:0)

尝试一下

final List<String> list=new ArrayList<>();

    list.add("jamshaid");
    list.add("jamshaid");
    list.add("jamshaid");
    list.add("jamshaid");
    list.add("jamshaid");

    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1, list);
    spinner.setAdapter(arrayAdapter);

答案 2 :(得分:0)

请尝试以下操作: 代码:

public class MainClass extends Activity {

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

    addOnSpinner();
}

private void addOnSpinner() {

    Spinner spinner = findViewById(R.id.spinner2);
    ArrayList<String> list = new ArrayList<>();

    list.add("A");
    list.add("B");

    ArrayAdapter adapter = new ArrayAdapter<String>( this, R.layout.support_simple_spinner_dropdown_item, list);
    spinner.setAdapter(adapter);
}

}

XML:

<FrameLayout
//layout
<LinearLayout
    android:id="@+id/tab3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFF"
    android:orientation="vertical">
    <Spinner
        android:id="@+id/spinner2"
        android:spinnerMode="dropdown"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
</LinearLayout>