In the below given code, I have basically used get()
method and displayed the data in TextView
, and I want to start another activity if the TextView
is empty, I have tried many options but it just won't work.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json");
SharedPreferences p = getActivity().getSharedPreferences("secret", Context.MODE_PRIVATE);
String token = p.getString("token", "");
params.put("Authorization", "Token " token);
PlaceHolderApi placeHolderApi = retrofit.create(PlaceHolderApi.class);
Call<List<profileDetails>> call=placeHolderApi.getDetails(params);
call.enqueue(new Callback<List<profileDetails>>() {
@Override
public void onResponse(Call<List<profileDetails>> call, Response<List<profileDetails>> response) {
List<profileDetails> data=response.body();
for (int i=0; i<data.size();i ){
name.append("" data.get(i).getFullname());
age.append("" data.get(i).getAge());
address.append("Address: " data.get(i).getLocation());
gender.append("Gender: " data.get(i).getGender());
num.append("Number: " data.get(i).getPhone_number());
uId.append("Id: " data.get(i).getId());
RoomId = Integer.parseInt(data.get(i).getId());}
}
@Override
public void onFailure(Call<List<profileDetails>> call, Throwable t) {
Log.e("kk","lal" t);
Toast.makeText(getContext(),"Error Cause : " t,Toast.LENGTH_LONG).show();
}
});
}
CodePudding user response:
it is not clear what you have already tried but let me give you a simple solution you can just check by
you_textview.setText("your text from server")
if(your_textview.getText().toString().isEmpty())
{
startActivity(new Intent(this,MainActivity.class));
}