こんにちは、listviewの座席を5列に表示する必要があるアプリを作っています.iynctaskを使ってjson.basedの値を解析して表示したい値に基づいています。私は必要なものイメージのようなjsonレスポンスからUIを更新するには
seats in listview.Please anybody tell me any logics to display seats like this.
をしてください表示する方法を教えてください: 私は何を取得しています:
を私のJSONです:私のJSON私はseat_name.ifのseat_nameを持っていて
[
{
"row1":[
{
"seat_name ":"A1",
"ticket_status":"booked",
"seatIsLadies":"true"
},
{
"seat_name ":"A2",
"ticket_status":"Not booked",
"seatIsLadies":"true"
},
{
"seat_name ":"A3",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A4",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A5",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A6",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A7",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A8",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A9",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A10",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"A11",
"ticket_status":"Not booked",
"seatIsLadies":"false"
}
],
"row2":[
{
"seat_name ":"B1",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B2",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B3",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B4",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B5",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B6",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B7",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B8",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B9",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B10",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"B11",
"ticket_status":"Not booked",
"seatIsLadies":"false"
}
],
"row3":[
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"NA",
"ticket_status":"",
"seatIsLadies":""
},
{
"seat_name ":"C11",
"ticket_status":"Not booked",
"seatIsLadies":"false"
}
],
"row5":[
{
"seat_name ":"D1",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D2",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D3",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D4",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D5",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D6",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D7",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D8",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D9",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D10",
"ticket_status":"Not booked",
"seatIsLadies":"false"
},
{
"seat_name ":"D11",
"ticket_status":"Not booked",
"seatIsLadies":"false"
}
]
}
]
はその後、我々はそうでない場合、我々は座席画像を表示するリストビューで空白を表示したいNAです。
私のコード: `
public class Seatparsing extends AsyncTask<String, String, ArrayList<HashMap<String, String>>> {
String response;
String jsonstr, seat_name, ticket_status, seatladies;
ProgressDialog dialog = new ProgressDialog(Seatvisible.this);
AndroidHttpClient maclient = AndroidHttpClient.newInstance("");
@Override
protected void onPreExecute() {
dialog.setCancelable(false);
dialog.setMessage("Please wait..");
dialog.setIndeterminate(false);
dialog.show();
}
@Override
protected ArrayList<HashMap<String, String>> doInBackground(String... params) {
HttpGet request = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
response = maclient.execute(request, responseHandler);
} catch (ClientProtocolException exception) {
exception.printStackTrace();
return null;
} catch (IOException exception) {
exception.printStackTrace();
return null;
}
Log.i("Seats", "" + response);
Log.i("seaturl", "" + url);
jsonstr = response;
busdetails1 = new ArrayList<>();
if (jsonstr != null) {
HashMap<String, String> map2 = new HashMap<>();
try {
JSONArray array1 = new JSONArray(jsonstr);
for (int i = 0; i < array1.length(); i++) {
JSONObject objct1 = array1.getJSONObject(i);
JSONArray array2 = objct1.getJSONArray("row1");
for (int j = 0; j < array2.length(); j++) {
JSONObject objct2 = array2.getJSONObject(j);
seat_name = objct2.getString("seat_name ").toString();
ticket_status = objct2.getString("ticket_status");
seatladies = objct2.getString("seatIsLadies");
map2.put("seat_name", seat_name);
map2.put("ticket_status", ticket_status);
map2.put("seatIsLadies", seatladies);
}
busdetails1.add(map2);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return busdetails1;
}
protected void onPostExecute(ArrayList<HashMap<String, String>> busdetails1) {
try {
dialog.dismiss();
customadapter adapter = new customadapter(getApplicationContext(), R.layout.seatlistview, busdetails1);
lv.setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class customadapter extends ArrayAdapter {
private ArrayList<HashMap<String, String>> list;
private int resource;
private LayoutInflater inflater;
public customadapter(Context context, int resource, ArrayList<HashMap<String, String>> busdetails1) {
super(context, resource, busdetails1);
list = busdetails1;
this.resource = resource;
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
}
@NonNull
@Override
public View getView(int i, View convertView, ViewGroup parent) {
convertView = inflater.inflate(resource, null);
ImageView imageView = (ImageView) convertView.findViewById(R.id.imageViewseat);
String seat_name = list.get(i).get("seat_name");
String ticket_status = list.get(i).get("ticket_status");
String seatIsLadies = list.get(i).get("seatIsLadies");
for(int l=0;l<busdetails1.size();l++) {
if (!seat_name.equals(null)) {
if (ticket_status.equals("booked")) {
if (seatIsLadies.equals("true")) {
imageView.setImageResource(R.drawable.reservedladies);
imageView.setClickable(false);
} else {
imageView.setImageResource(R.drawable.bookedseat);
imageView.setClickable(false);
}
} else {
imageView.setImageResource(R.drawable.available_seat_img);
}
} else {
imageView.setImageDrawable(null);
imageView.setClickable(false);
}
}
return convertView;
}
}`
私のxmlファイル:リストビューのための`
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_seatvisible"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.notebook.runtowin.Activity.Seatvisible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/from_to"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark"
android:text="Select your seat"
android:padding="5dp"
android:gravity="center_vertical"
android:textStyle="bold"
android:textColor="@color/colorwhite" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/from_to">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#FFEB3B"
android:id="@+id/headinglayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/busname"
android:padding="5dp"
android:text="RUN TO WIN"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/busname"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seatnumber"
android:padding="5dp"
android:text="Seats :"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:text="25,24"
android:id="@+id/seatsnumber"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ticketprice"
android:layout_alignParentRight="true"
android:text="hsdshd"
android:textStyle="bold"
android:padding="5sp"
android:textSize="30sp"
android:layout_marginRight="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/headinglayout"
android:layout_marginTop="3dp"
android:paddingTop="10dp"
android:paddingRight="25dp"
android:paddingLeft="25dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/iconsteer"
android:id="@+id/imageView2"
android:layout_marginEnd="50dp"
android:layout_alignParentEnd="true"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView2"
android:layout_marginTop="20dp"
android:numColumns="5"
android:id="@+id/listviewseat">
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentEnd="true"
android:gravity="center_horizontal"
android:background="@color/colorPrimaryDark"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BOOK TICKETS"
android:padding="10dp"
android:id="@+id/bt_book"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
私のxmlファイル:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8sp"
android:gravity="top">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageViewseat"/>
</LinearLayout>
少なくとも「空白」(および「ヌル」ではない)のイメージが必要です。そうでない場合、サイズが正しく設定されません。また、膨らんでいるビューのXMLも提供します。また、 'ListView'はグリッド表示のための良い選択ではありません。 –
私のXMLファイルを編集して上に追加しました – lucky
@ escape-llc..thankyou for ur reply..i編集したコード – lucky