我傳遞了導航滑塊中的JSON,其中它獲取的差距2項之間的空隙差距。我無法理解爲什麼會發生這種情況。我曾嘗試過幾種方法,但我不成功。在Android中的循環創建項目之間的差距
Navigation.Java
private void navmenu() {
String menuurl = "http://www.souqalkhaleejia.com/webapis/categories.php";
Log.i("menuurl", menuurl);
JsonObjectRequest menuobj = new JsonObjectRequest(Request.Method.POST, menuurl, (String) null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray menu1=response.getJSONArray("menu1");
for (int i=0;i<menu1.length();i++){
JSONObject first=menu1.getJSONObject(i);
Data navgadata = new Data();
navgadata.setCatergory(first.getString("category"));
datalts.add(navgadata);
JSONArray item=first.getJSONArray("items");
for (int j=0;j<item.length();j++){
Data secdata=new Data();
JSONObject second=item.getJSONObject(j);
secdata.setId(second.getString("id"));
secdata.setSubcatergory(second.getString("title"));
datalts.add(secdata);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
listnadapter.notifyDataSetChanged();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("res", "Error: " + error.getMessage());
}
});
AppController.getInstance().addToRequestQueue(menuobj);
}
這是我的XML文件navigation.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:textColor="#fff"
android:id="@+id/categories" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:textColor="#fff"
android:id="@+id/subcategories" />
Adapter.java
public class Navgation_adapter extends BaseAdapter {
private Context context;
private List<Data> catdata;
private LayoutInflater inflater;
public Navgation_adapter(Context context, List<Data> catdata){
this.context=context;
this.catdata=catdata;
}
@Override
public int getCount() {
return catdata.size();
}
@Override
public Object getItem(int i) {
return catdata.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder holder;
if (inflater == null)
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(view==null){
holder=new ViewHolder();
view=inflater.inflate(R.layout.navigation_list,viewGroup,false);
holder.categories= (TextView) view.findViewById(R.id.categories);
holder.subcategories= (TextView) view.findViewById(R.id.subcategories);
view.setTag(holder);
}else {
holder= (ViewHolder) view.getTag();
}
Data ndata=catdata.get(i);
holder.categories.setText(ndata.getCatergory());
holder.subcategories.setText(ndata.getSubcatergory());
return view;
}
static class ViewHolder{
TextView categories,subcategories;
}
在這裏,我怎麼得到視圖
你在使用什麼適配器?如果是自定義的,請發佈。實際上,它看起來像是將列表項佈局中的一個TextViews設置爲「INVISIBLE」,具體取決於它是類別還是子類別。如果是這樣的話,你應該使用'GONE'來代替。但如果這不是問題,請張貼適配器。 –
我已更新帖子,請檢查 –
我沒有使用任何可見或不可見的 –