Вот код:
package com.example.hondle.biling.fragments;
public class contracts extends Fragment {
public final String TAG = "contracts";
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
CatTask cattask;
RecyclerViewAdapter rcAdapter;
RecyclerView rView;
private OnFragmentInteractionListener mListener;
private LinearLayoutManager lLayout;
public String[] contractId = new String[100];
public static contracts newInstance(String param1, String param2) {
contracts fragment = new contracts();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_contracts, container, false);
Log.d(TAG, "Start");
cattask = new CatTask();
cattask.execute();
List<ItemObject> rowListItem = getAllItemList();
lLayout = new LinearLayoutManager(getActivity());
rView = (RecyclerView)view.findViewById(R.id.recycler_view);
rView.setLayoutManager(lLayout);
rcAdapter = new RecyclerViewAdapter(getActivity(), rowListItem);
rView.setAdapter(rcAdapter);
return view;
}
private List<ItemObject> getAllItemList(){
List<ItemObject> allItems = new ArrayList<ItemObject>();
allItems.add(new ItemObject(contractId[0], "6"));
allItems.add(new ItemObject(contractId[1], "2"));
allItems.add(new ItemObject("Ближайший офис", "3"));
allItems.add(new ItemObject("Заказать звонок", "4"));
allItems.add(new ItemObject("Позвонить в контактный центр", "5"));
return allItems;
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
class CatTask extends AsyncTask<Void, Void, Void> {
public String token = getActivity().getIntent().getExtras().getString("access_token");
TextView text;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
Log.d(TAG, "start");
Log.d(TAG, token);
String token = getActivity().getIntent().getExtras().getString("access_token");
Log.d(TAG, token);
DefaultHttpClient hc = new DefaultHttpClient();
ResponseHandler GetResponse = new BasicResponseHandler();
HttpGet http = new HttpGet("mysite.openregion.info/api/v1.3.0/contract/getlist?access_token=" + token);
try {
String response = (String) hc.execute(http, GetResponse);
Log.d(TAG, response);
JSONObject jobj = new JSONObject(response);
JSONArray contracts = jobj.getJSONArray("contracts");
String contract = contracts.getString(0);
for (int i = 0; i < contracts.length(); i++) {
contractId[i] = String.valueOf(contracts.get(i));
HttpGet http2 = new HttpGet("mysite.info/api/v1.3.0/contract/counters?contract_id=" + contract);
Log.d(TAG, contractId[i]);
try {
String Cresponse = (String) hc.execute(http2, GetResponse);
Log.d(TAG, Cresponse);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (IOException | JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
rcAdapter.notifyDataSetChanged();
}
}
}
Вроде бы все работает, логирование показывает что все нормальное, но на экране данные не обновляются.