我有一个包含从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
我检查了五次。它的未来正确 –