PilihKursiZ.java

package com.example.tiketku;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.Button;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


public class PilihKursiZ extends AppCompatActivity {
    List<ExampleBus> mExampleList;

    private static final String URL_PRODUCTS = "http://192.168.1.7/api_mysql_tiketbus/kursibus.php";

    Intent intent = getIntent();

    String Id_bus, Nama_bus, Asal_bus, Tujuan_bus, Waktu_bus, Harga_bus;

    Button btnkursilanjut;
    ImageView a1, b1, c1, d1, e1,
            a2, b2, c2, d2, e2,
            a3, b3, c3, d3, e3,
            a4, b4, c4, d4, e4,
            a5, b5, c5, d5, e5,
            a6, b6, c6, d6, e6,
            a7, b7, c7, d7, e7;

    String namaBus;

    int a1_click=0, b1_click=0, c1_click=0, d1_click=0, e1_click=0;
    int a2_click=0, b2_click=0, c2_click=0, d2_click=0, e2_click=0;
    int a3_click=0, b3_click=0, c3_click=0, d3_click=0, e3_click=0;
    int a4_click=0, b4_click=0, c4_click=0, d4_click=0, e4_click=0;
    int a5_click=0, b5_click=0, c5_click=0, d5_click=0, e5_click=0;
    int a6_click=0, b6_click=0, c6_click=0, d6_click=0, e6_click=0;
    int a7_click=0, b7_click=0, c7_click=0, d7_click=0, e7_click=0;

    String cek="";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pilihkursiz);
        btnkursilanjut = (Button) findViewById(R.id.btnkursilsnjut);
    //    Id_bus = intent.getIntExtra("id_bus",0);
        Intent intent = getIntent();
        Id_bus = intent.getStringExtra("id_bus");
        Nama_bus = intent.getStringExtra("nama_bus");
        Asal_bus = intent.getStringExtra("asal_bus");
        Tujuan_bus = intent.getStringExtra("tujuan_bus");
        Waktu_bus = intent.getStringExtra("waktu_bus");
        Harga_bus = intent.getStringExtra("harga_bus");

        StringRequest stringRequest = new StringRequest(Request.Method.GET,URL_PRODUCTS + "?id_bus=" +Id_bus,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            //converting the string to json array object
                            JSONArray array = new JSONArray(response);

                            //traversing through all the object
                            for (int i = 0; i < array.length(); i++) {

                                //getting product object from json array
                                JSONObject bus = array.getJSONObject(i);

                                        bus.getInt("id_bus");
                                        namaBus = bus.getString("nama_bus");
                                        bus.getString("asal_bus");
                                        bus.getString("harga");
                                        bus.getString("tujuan_bus");
                                        bus.getString("waktu_bus");
                              //=====================================================================

                                a1_click = Integer.parseInt(bus.getString("kursi_a1"));
                                b1_click = Integer.parseInt(bus.getString("kursi_b1"));
                                c1_click = Integer.parseInt(bus.getString("kursi_c1"));
                                d1_click = Integer.parseInt(bus.getString("kursi_d1"));
                                e1_click = Integer.parseInt(bus.getString("kursi_e1"));

                                a2_click = Integer.parseInt(bus.getString("kursi_a2"));
                                b2_click = Integer.parseInt(bus.getString("kursi_b2"));
                                c2_click = Integer.parseInt(bus.getString("kursi_c2"));
                                d2_click = Integer.parseInt(bus.getString("kursi_d2"));
                                e2_click = Integer.parseInt(bus.getString("kursi_e2"));

                                a3_click = Integer.parseInt(bus.getString("kursi_a3"));
                                b3_click = Integer.parseInt(bus.getString("kursi_b3"));
                                c3_click = Integer.parseInt(bus.getString("kursi_c3"));
                                d3_click = Integer.parseInt(bus.getString("kursi_d3"));
                                e3_click = Integer.parseInt(bus.getString("kursi_e3"));

                                a4_click = Integer.parseInt(bus.getString("kursi_a4"));
                                b4_click = Integer.parseInt(bus.getString("kursi_b4"));
                                c4_click = Integer.parseInt(bus.getString("kursi_c4"));
                                d4_click = Integer.parseInt(bus.getString("kursi_d4"));
                                e4_click = Integer.parseInt(bus.getString("kursi_e4"));

                                a5_click = Integer.parseInt(bus.getString("kursi_a5"));
                                b5_click = Integer.parseInt(bus.getString("kursi_b5"));
                                c5_click = Integer.parseInt(bus.getString("kursi_c5"));
                                d5_click = Integer.parseInt(bus.getString("kursi_d5"));
                                e5_click = Integer.parseInt(bus.getString("kursi_e5"));

                                a6_click = Integer.parseInt(bus.getString("kursi_a6"));
                                b6_click = Integer.parseInt(bus.getString("kursi_b6"));
                                c6_click = Integer.parseInt(bus.getString("kursi_c6"));
                                d6_click = Integer.parseInt(bus.getString("kursi_d6"));
                                e6_click = Integer.parseInt(bus.getString("kursi_e6"));

                                a7_click = Integer.parseInt(bus.getString("kursi_a7"));
                                b7_click = Integer.parseInt(bus.getString("kursi_b7"));
                                c7_click = Integer.parseInt(bus.getString("kursi_c7"));
                                d7_click = Integer.parseInt(bus.getString("kursi_d7"));
                                e7_click = Integer.parseInt(bus.getString("kursi_e7"));
                           //========================================================================
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                    }
                });
        Toast.makeText(this,namaBus,Toast.LENGTH_LONG).show();
        a1 = (ImageView) findViewById(R.id.a1);
        b1 = (ImageView) findViewById(R.id.b1);
        c1 = (ImageView) findViewById(R.id.c1);
        d1 = (ImageView) findViewById(R.id.d1);
        e1 = (ImageView) findViewById(R.id.e1);

        a2 = (ImageView) findViewById(R.id.a2);
        b2 = (ImageView) findViewById(R.id.b2);
        c2 = (ImageView) findViewById(R.id.c2);
        d2 = (ImageView) findViewById(R.id.d2);
        e2 = (ImageView) findViewById(R.id.e2);

        a3 = (ImageView) findViewById(R.id.a3);
        b3 = (ImageView) findViewById(R.id.b3);
        c3 = (ImageView) findViewById(R.id.c3);
        d3 = (ImageView) findViewById(R.id.d3);
        e3 = (ImageView) findViewById(R.id.e3);

        a4 = (ImageView) findViewById(R.id.a4);
        b4 = (ImageView) findViewById(R.id.b4);
        c4 = (ImageView) findViewById(R.id.c4);
        d4 = (ImageView) findViewById(R.id.d4);
        e4 = (ImageView) findViewById(R.id.e4);

        a5 = (ImageView) findViewById(R.id.a5);
        b5 = (ImageView) findViewById(R.id.b5);
        c5 = (ImageView) findViewById(R.id.c5);
        d5 = (ImageView) findViewById(R.id.d5);
        e5 = (ImageView) findViewById(R.id.e5);

        a6 = (ImageView) findViewById(R.id.a6);
        b6 = (ImageView) findViewById(R.id.b6);
        c6 = (ImageView) findViewById(R.id.c6);
        d6 = (ImageView) findViewById(R.id.d6);
        e6 = (ImageView) findViewById(R.id.e6);

        a7 = (ImageView) findViewById(R.id.a7);
        b7 = (ImageView) findViewById(R.id.b7);
        c7 = (ImageView) findViewById(R.id.c7);
        d7 = (ImageView) findViewById(R.id.d7);
        e7 = (ImageView) findViewById(R.id.e7);
//===================================================================================
        if (a1_click == 1){
            a1.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a1.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b1_click == 1){
            b1.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b1.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c1_click == 1){
            c1.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c1.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d1_click == 1){
            d1.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d1.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e1_click == 1){
            e1.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e1.setBackgroundColor(Color.parseColor("#999797"));
        }
      //22222222222222222222222222222222222222
        if (a2_click == 1){
            a2.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a2.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b2_click == 1){
            b2.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b2.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c2_click == 1){
            c2.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c2.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d2_click == 1){
            d2.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d2.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e2_click == 1){
            e2.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e2.setBackgroundColor(Color.parseColor("#999797"));
        }
      //33333333333333333333333333333
        if (a3_click == 1){
            a3.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a3.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b3_click == 1){
            b3.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b3.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c3_click == 1){
            c3.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c3.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d3_click == 1){
            d3.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d3.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e3_click == 1){
            e3.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e3.setBackgroundColor(Color.parseColor("#999797"));
        }
      //44444444444444444444444444444444444444444444444444
        if (a4_click == 1){
            a4.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a4.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b4_click == 1){
            b4.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b4.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c4_click == 1){
            c4.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c4.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d4_click == 1){
            d4.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d4.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e4_click == 1){
            e4.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e4.setBackgroundColor(Color.parseColor("#999797"));
        }
       //5555555555555555555555555555555555555555
        if (a5_click == 1){
            a5.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a5.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b5_click == 1){
            b5.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b5.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c5_click == 1){
            c5.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c5.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d5_click == 1){
            d5.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d5.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e5_click == 1){
            e5.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e5.setBackgroundColor(Color.parseColor("#999797"));
        }
       //666666666666666666666666666666666
        if (a6_click == 1){
            a6.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a6.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b6_click == 1){
            b6.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b6.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c6_click == 1){
            c6.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c6.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d6_click == 1){
            d6.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d6.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e6_click == 1){
            e6.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e6.setBackgroundColor(Color.parseColor("#999797"));
        }
       // 777777777777777777777
        if (a7_click == 1){
            a7.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            a7.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (b7_click == 1){
            b7.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            b7.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (c7_click == 1){
            c7.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            c7.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (d7_click == 1){
            d7.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            d7.setBackgroundColor(Color.parseColor("#999797"));
        }

        if (e7_click == 1){
            e7.setBackgroundColor(Color.parseColor("#F80320"));
        }else{
            e7.setBackgroundColor(Color.parseColor("#999797"));
        }
//==============================================================================================
        a1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (a1_click == 0){
                    a1.setBackgroundColor(Color.parseColor("#03A9F4"));
                    a1_click = 1;
                }else{
                    a1.setBackgroundColor(Color.parseColor("#999797"));
                    a1_click = 0;
                }
            }
        });

        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (b1_click == 0){
                    b1.setBackgroundColor(Color.parseColor("#03A9F4"));
                    b1_click = 1;
                }else{
                    b1.setBackgroundColor(Color.parseColor("#999797"));
                    b1_click = 0;
                }
            }
        });

        c1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (c1_click == 0){
                    c1.setBackgroundColor(Color.parseColor("#03A9F4"));
                    c1_click = 1;
                }else{
                    c1.setBackgroundColor(Color.parseColor("#999797"));
                    c1_click = 0;
                }
            }
        });

        d1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (d1_click == 0){
                    d1.setBackgroundColor(Color.parseColor("#03A9F4"));
                    d1_click = 1;
                }else{
                    d1.setBackgroundColor(Color.parseColor("#999797"));
                    d1_click = 0;
                }
            }
        });

        e1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (e1_click == 0){
                    e1.setBackgroundColor(Color.parseColor("#03A9F4"));
                    e1_click = 1;
                }else{
                    e1.setBackgroundColor(Color.parseColor("#999797"));
                    e1_click = 0;
                }
            }
        });

Add a code snippet to your website: www.paste.org