gpt4 book ai didi

android - 如何使座位布局像redbus?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:10:01 24 4
gpt4 key购买 nike

如何在每行 3 个元素之后的 GridView 中留出空间?

seat preview

预期 View 如下:

expected seat preview .

这是我的主要 Activity 代码。请检查我上面给出的屏幕我想要在 android 中的 GridView 内留出空间,如何在每行的 3 个元素之后在 GridView 内留出空间?

    public  void submit() {

String URLL= "https://api.myjson.com/bins/14h7rp";
StringRequest stringRequest = new StringRequest(Request.Method.GET, URLL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {


try {
JSONObject object=new JSONObject(response);
String status=object.getString("Status");
String Data=object.getJSONObject("Data").getString("Seat_details");
JSONArray jsonArray=new JSONArray(Data);
for (int i=0;i<jsonArray.length();i++){
JSONObject J=jsonArray.getJSONObject(i);
String seats=J.getString("seats");
JSONArray jsonArray1=new JSONArray(seats);
for (int k=0;k<jsonArray1.length();k++){
JSONObject l=jsonArray1.getJSONObject(k);
String id=l.getString("id");
String name=l.getString("name");

String bookedStatus=l.getString("bookedStatus");

m=new Model();
m.setId(id);
m.setName(name);

m.setBookedStatus(bookedStatus);
arrayList.add(m);

}

}
} catch (JSONException e) {
e.printStackTrace();
}
adapter=new MainActivityAdapter(arrayList,MainActivity.this);
recyclerView.setAdapter(adapter);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
}) {
@Override
}

}

我的Recylerview初始化如下

 private void init_views() {
recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.spacing);
recyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getApplicationContext(),5);
recyclerView.setLayoutManager(layoutManager);
/* DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
layoutManager.getOrientation(layoutManager));
recyclerView.addItemDecoration(dividerItemDecoration);*/
}

最佳答案

你会得到答案的一种方式,但这不是正确的方式

                      try {
JSONObject object=new JSONObject(response);
String status=object.getString("Status");
String Data=object.getJSONObject("Data").getString("Seat_details");
// System.out.println("_______Data_________" + Data);
JSONArray jsonArray=new JSONArray(Data);
for (int i=0;i<jsonArray.length();i++){
JSONObject J=jsonArray.getJSONObject(i);
String seats=J.getString("seats");
JSONArray jsonArray1=new JSONArray(seats);

for (int k=0;k<jsonArray1.length();k++){
if (k%COLUMNS==3) {

m=new Model();
m.setId("");
m.setName("");
m.setSeatKey("");
m.setRowNumber("");
m.setColumnIndex("");
m.setBookedStatus("2");
arrayList.add(m);
} else{
JSONObject l=jsonArray1.getJSONObject(k);
String id=l.getString("id");
String name=l.getString("name");
String seatKey=l.getString("seatKey");
String rowNumber=l.getString("rowNumber");
String columnIndex=l.getString("columnIndex");
String bookedStatus=l.getString("bookedStatus");
System.out.println("______name_________" + name);

m=new Model();
m.setId(id);
m.setName(name);
m.setSeatKey(seatKey);
m.setRowNumber(rowNumber);
m.setColumnIndex(columnIndex);
m.setBookedStatus(bookedStatus);
arrayList.add(m);

}


}

}
} catch (JSONException e) {
e.printStackTrace();
}

声明列变量

  private static final int COLUMNS = 6;

关于android - 如何使座位布局像redbus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48004281/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com