下面的代码我已经成功显示了数据,但是使用了recyclerView。我想问如果使用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) {
}
});
}
<?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);
}
这是我的 php json
如果您不使用数据的ArrayList,则只需在响应正文中添加此行 请看下面的代码
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
}
}
如果还没有解决请告诉我