Проблема в том, что данные с параметром user_id
не отображаются в recylerView.Я пытался с помощью многих вариантов метода, таких как изменения user_id
на session_id
в качестве параметра, но он все еще не работает.Я создаю это приложение с помощью метода POST, GET и т. Д. С использованием retrofit2.
Это json, когда я выполняю на инструменте почтальона "после успешного входа в систему":
http://localhost/web/api/transaction/findAll
{
//"session_id": "93enj0lcs4catvps6ars7u1rlba8vvig",
"user_id":74,
"success": true,
"result": [
{
"id": "232",
"user_id": "74",
"item_code": "B002",
"qty": "2",
"price": "150",
"total_price": "300"
},
{
"id": "233",
"user_id": "74",
"item_code": "B002",
"qty": "2",
"price": "150",
"total_price": "300"
}
]
}
Это код части activity_transaction:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transaction);
this.setTitle("INVOICE TRANSACTION");
session = new SessionManagement(getApplicationContext());
HashMap<String, String> user = session.getUserDetails();
final String userid = user.get(SessionManagement.KEY_USERID);
final String sessionid = user.get(SessionManagement.KEY_SESSIONID);
txt_userid = (TextView) findViewById(R.id.txt_userid);
txt_userid.setText(userid);
txtsession_id = (TextView) findViewById(R.id.txtsession_id);
txtsession_id.setText(sessionid);
final String user_id = txt_userid.getText().toString();
final String session_id = txtsession_id.getText().toString();
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(mManager);
adapter = new TransactionAdapter(transactionList, getApplicationContext());
recyclerView.setAdapter(adapter);
TransactionService transactionService = APIClient.getClient().create(TransactionService.class);
//before
//Call<ResponseTransaction> call = transactionService.getFindAll(session_id);
Call<ResponseTransaction> call = transactionService.getFindAll();
call.enqueue(new Callback<ResponseTransaction>() {
@Override
public void onResponse(Call<ResponseTransaction> call, Response<ResponseTransaction> response) {
// i think my problem in arround these line
if (response.isSuccessful()) {
ResponseTransaction responseTransaction = response.body();
if (responseTransaction.getSuccess().equals("true")) {
transactionList = response.body().getResult();
adapter = new TransactionAdapter(transactionList, getApplicationContext());
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}else {
Toast.makeText(TransationActivity.this, "DATA IS EMPTY", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<ResponseTransaction> call, Throwable t) {
Toast.makeText(TransationActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
Это код интерфейсов
public interface TransactionService {
/*Before*/
//@GET("transaction/findAll")
// Call<ResponseTransaction> getFindAll(@Query("session_id") String session_id);
/*NOW*/
@GET("transaction/findAll")
Call<ResponseTransaction> getFindAll();
}
Это часть моего TransactionAdapter:
public class TransactionAdapter extends RecyclerView.Adapter<TransactionAdapter.ViewHolder> {
private List<Transaction> transactionList = new ArrayList();
private Context context;
public TransactionAdapter(List<Transaction> transactionList, Context context) {
this.transactionList = transactionList;
this.context = context;
}
@Override
public TransactionAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.transaction_list, parent, false);
TransactionAdapter.ViewHolder viewHolder = new TransactionAdapter.ViewHolder(v, context, transactionList);
return viewHolder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
Transaction item = transactionList.get(position);
holder.bind(item);
}
@Override
public int getItemCount() {
return transactionList.size();
}
static class ViewHolder extends RecyclerView.ViewHolder {
TextView txtId;
TextView txtItem_code;
TextView txtQty;
TextView txtPrice;
TextView txtTotal_price;
TextView txtsessionID;
private Transaction currentItem;
Context context;
ViewHolder(View itemView, Context context, List<Transaction> transactionList) {
super(itemView);
this.context = context;
txtId = (TextView) itemView.findViewById(R.id.txtId);
txtId.setVisibility(View.GONE);
txtsessionID = (TextView) itemView.findViewById(R.id.txtsessionID);
txtsessionID.setVisibility(View.GONE);
txtItem_code = (TextView) itemView.findViewById(R.id.txtItem_code);
txtQty = (TextView) itemView.findViewById(R.id.txtQty);
txtPrice = (TextView) itemView.findViewById(R.id.txtPrice);
}
void bind(Transaction item) {
txtId.setText(String.valueOf(item.getId()));
txtsessionID.setText(String.valueOf(item.getSession_id()));
txtItem_code.setText(item.getItem_code());
txtQty.setText(String.valueOf(item.getQty()));
txtPrice.setText(String.valueOf(item.getPrice()));
currentItem = item;
}
}
Это часть моего API:
function findAll_get(){
$infoLogin = $this->session->userdata('isLoggedIn');
$sessiondt = $infoLogin;
$this->load->model('M_transaction');
$user_id = $sessiondt ['user_id'];
$query = $this->M_transaction->get_all($user_id);
if($query){
$this->response(['user_id'=>$user_id, 'success'=>true, 'result'=>$query ],REST_Controller::HTTP_OK);
}
else
{
$this->response(['user_id'=>$user_id, 'success'=>false, 'result'=>'access disallowed'], REST_Controller::HTTP_BAD_REQUEST);
}
}
Заранее спасибо.