我有一個包含從Web服務項的微調..微調的項目在下拉列表中不可見
這個代碼是
JsonArrayRequest fillspinner = new JsonArrayRequest(GET_SPINNER_ITEM, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
try{
for(int i =0;i<=response.length();i++){
JSONObject obj = response.getJSONObject(i);
names = obj.getString("Name");
itemnames.add(names);
}
} catch (JSONException e) {
e.printStackTrace();
}
ArrayAdapter<String> adap = new ArrayAdapter<>(getApplicationContext(),android.R.layout.simple_spinner_item,itemnames);
spinner.setAdapter(adap);
adap.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
fillspinner.setRetryPolicy(new DefaultRetryPolicy(
30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
VolleyApplication.getInstance().getRequestQueue().add(fillspinner);
}
和我layout.xml是
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/drawer_layout"
tools:context=".ActivityClasses.MainActivity"
android:fitsSystemWindows="true">
<include android:id="@+id/toolbar" layout="@layout/toolbar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="@dimen/welbtnmargin">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple"
android:textColor="@color/white"
android:id="@+id/date"
android:layout_marginBottom="@dimen/btnsepration"
android:text="-"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Expenses"
android:gravity="center"
android:layout_marginBottom="@dimen/btnsepration"
android:layout_gravity="center"/>
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ms_arrow_tint="@color/white"
app:ms_text_color="@color/white"
app:ms_background_color="@color/colorPrimaryDark"/>
<EditText
android:layout_width="match_parent"
android:layout_height="@dimen/header_height"
android:elevation="4dp"
/>
</LinearLayout>
我的問題是當我點擊微調,我得到這樣的輸出。
there are items in the spinner but they are not visible
當我點擊的項目它的微調得到選擇。但在下拉列表中不可見。我試圖在適配器中膨脹我自己的佈局,仍然得到相同的結果。
我覺得你的代碼是OK,再次檢查JSON陣列響應... – Omi
你檢查,在JSON響應'Name' attr爲不爲空字符串? – chandil03
我檢查了五次。它的未來正確 –