Home > Software design >  how to output data from xampp to Textview
how to output data from xampp to Textview

Time:06-30

the code below I have successfully displayed the data but using the recyclerView. I want to ask how to display data if using Textview?

private void loadDataMahasiswa() {
        progress = new ProgressDialog(this);
        progress.setCancelable(false);
        progress.setMessage("Loading ...");
        progress.show();

        String nip = editTxtnip.getText().toString();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        LoginAPI api = retrofit.create(LoginAPI.class);
        Call<Value> call = api.view3(nip);
        call.enqueue(new Callback<Value>() {
            @Override
            public void onResponse(Call<Value> call, Response<Value> response) {
                String value = response.body().getValue();
                progress.dismiss();
                if (value.equals("1")) {

                    results = response.body().getResult();
                    viewAdapter = new RecyclerViewAdapter3(Lihat_izin.this, results);
                    recyclerView.setAdapter(viewAdapter);
                }
            }

            @Override
            public void onFailure(Call<Value> call, Throwable t) {

            }
        });
    }

CodePudding user response:

If you are not using ArrayList of data then just add this line inside the response body See below code

public void onResponse(Call<Value> call, Response<Value> response) {
                String value = response.body().getValue();
                progress.dismiss();
                if (value.equals("1")) {
                    results = response.body().getResult();
                    viewAdapter = new RecyclerViewAdapter3(Lihat_izin.this, results);
                    recyclerView.setAdapter(viewAdapter);
                    String myData = response.body().toString(); // convert data to string
                    textView.setText(myData); // just add data to textView
                }
            }

Let me know if not solved yet

CodePudding user response:

the results of the variables above are not readable sir

CodePudding user response:

<?php
require_once('dbConnect.php');
date_default_timezone_set("Asia/Jakarta");
$timestamp = date('Y-m-d');
if($_SERVER['REQUEST_METHOD']=='GET') 
  $opd = $_GET['opd'];{
  $sql = "SELECT COUNT(*)FROM(SELECT DISTINCT waktu,status from absen_pagi where opd='$opd' AND waktu='$timestamp')as dt";
  $res = mysqli_query($con,$sql);
  $result = array();
  while($row = mysqli_fetch_array($res)){
    array_push($result, array('waktu'=>$row['COUNT(*)']));
  }
  echo json_encode(array("value"=>1,"result"=>$result));
  mysqli_close($con);
}

this my php json

  • Related