2016-12-07 5 views
0

私のコード内に、私は改造を使用してAPIを呼び出しています。 (response.isSuccessful())がそのブレークポイントにヒットしない場合、私は回線にブレークポイントを入れました。 私はこの問題がなぜ発生するのかを知りたいのですが、 と同じコードを別のフラグメントに配置してもうまくいきましたので、 の結果をAPIから取得できましたが、このフラグメントでは呼び出しは機能しません。私はまた、public void onFailureにブレークポイントを設定して、 がコールに失敗した可能性がありますが、そのブレークポイントも決してヒットしないことを確認します。これは、サーバーへのコールが何らかの理由で失敗していないことを意味します。 public void OnResponseがスキップされています。 私は今、改造呼出しを使用している私の断片の中にコードがあることを疑っています。 私はそれが非同期したがって、その呼び出しを行うので、私は、私は改造と競合する別のメソッドを呼び出すと思ったその直後、その後のAPI呼び出しを行うメソッドを呼び出すようにしようとしていたリクエストが正常に完了していないときに、Retrofitでエンキューコール関数をデバッグする方法

package com.xera.deviceinsight.home; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import android.content.Context; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.support.v4.view.ViewPager; 
import android.util.Log; 
import android.view.View; 
//import android.widget.ExpandableListAdapter; 
import android.widget.ExpandableListView; 
import android.widget.Toast; 
import android.support.annotation.Nullable; 
import android.view.LayoutInflater; 
import android.view.ViewGroup; 
import com.androidquery.AQuery; 
import com.xera.deviceinsight.Errors; 
import com.xera.deviceinsight.Globals; 
import com.xera.deviceinsight.R; 
import com.xera.deviceinsight.api.OrganisationDeviceSensorsResult; 
import com.xera.deviceinsight.api.Results; 
import com.xera.deviceinsight.net.Claritech; 
import com.xera.deviceinsight.net.ClaritechClient; 
import com.xera.deviceinsight.receivers.IEvent; 
import com.xera.deviceinsight.sensors.IotTabFragment; 
import com.xera.deviceinsight.sensors.ItemClickedEvent; 
import com.xera.deviceinsight.structs.DistanceUpdatedEvent; 
import com.xera.deviceinsight.structs.HelloWorldEvent; 
import com.xera.deviceinsight.structs.OrganisationDeviceSensorsEvent; 

import de.greenrobot.event.EventBus; 
import retrofit2.Call; 
import retrofit2.Callback; 
import retrofit2.Response; 

public class CostCentreListFragment extends Fragment { 

    public static final String TAG = Globals.TAG + ".ALF"; 
    ViewPager mViewPager; 
    ExpandableListAdapter listAdapter; 
    ExpandableListView expListView; 
    List<String> listDataHeader; 
    HashMap<String, List<String>> listDataChild; 
    public List<OrganisationDeviceSensorsResult> Items; 
    public String currentReportingGroup; 
    private ViewPager viewPager; 
    private IEvent onDeviceSensorsObtained; 
    private IEvent event; 
    public List sensorList; 


    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
     //EventBus eventBus = EventBus.getDefault(); 
    // if (!eventBus.isRegistered(this)) eventBus.register(this); 
     View view = inflater.inflate(R.layout.layout_expandable, container, false); 
     AQuery aq = new AQuery(view); 
     getDeviceSensorCostCentres(); 
     load(view); 
     return view; 
    } 

    private void load(View view) 
    { 
     expListView = (ExpandableListView) view.findViewById(R.id.lvExp); 
     //EventBus.getDefault().post(new ItemClickedEvent(IotTabFragment.TAB_SENSOR)); 
     getDeviceSensorCostCentres(); 
     prepareListData(); 
     listAdapter = new ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild); 
     expListView.setAdapter(listAdapter); 
     expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 
     @Override 
     public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
      //Nothing here ever fires 
      System.err.println("child clicked"); 
      Toast.makeText(getActivity(), "child clicked", Toast.LENGTH_SHORT).show(); 

      // Navigate to second tab 
      // EventBus.getDefault().post(new ItemClickedEvent(IotTabFragment.TAB_SENSOR)); 
      EventBus.getDefault().post(new ItemClickedEvent(IotTabFragment.TAB_USAGE)); 
      return true; 
     } 
     }); 
    } 
    @Override 
    public void onStart() { 
     super.onStart(); 
     EventBus.getDefault().register(this); 
    } 
    @Override 
    public void onPause() { 
     EventBus.getDefault().unregister(this); 
     super.onPause(); 
    } 
    private void getDeviceSensorCostCentres() { 
     //int costCentreID =0 
     final Context context = this.getActivity(); 
     ClaritechClient client = new ClaritechClient(context); 

     Claritech.api(context).getDeviceSensorCostCentres(0).enqueue(new Callback<Results<OrganisationDeviceSensorsResult>>() { 
     @Override 
     public void onResponse(Call<Results<OrganisationDeviceSensorsResult>> call, Response<Results<OrganisationDeviceSensorsResult>> response) { 

      if (response.isSuccessful()) { 
       // Reload data source 
       Items.clear(); 
       Items.addAll(response.body()); 
       //ItemsAdapter.notifyDataSetChanged(); 
       Log.i(TAG, "onResponse: "); 
      } 
     } 
     @Override 
     public void onFailure(Call<Results<OrganisationDeviceSensorsResult>> call, Throwable t) { 
      Errors.handleException(t); 


     } 
    }); 
    } 


    public void onEvent(OrganisationDeviceSensorsEvent event){ 
     String Tag =""; 
     sensorList = event.deviceSensors; 
     Log.i("EventBus",Tag); 
     //prepareSensorListData(); 
     //Toast.makeText(getActivity(), event.deviceSensors, Toast.LENGTH_SHORT).show(); 
    }; 

    private void prepareListData() { 
     listDataHeader = new ArrayList<String>(); 
     listDataChild = new HashMap<String, List<String>>(); 
     // Adding child data 
     listDataHeader.add("Top 250"); 
     listDataHeader.add("Now Showing"); 
     listDataHeader.add("Coming Soon.."); 
     List<String> top250 = new ArrayList<String>(); 
     top250.add("The Shawshank Redemption"); 
     top250.add("The Godfather"); 
     top250.add("The Godfather: Part II"); 
     top250.add("Pulp Fiction"); 
     top250.add("The Good, the Bad and the Ugly"); 
     top250.add("The Dark Knight"); 
     top250.add("12 Angry Men"); 

     List<String> nowShowing = new ArrayList<String>(); 
     nowShowing.add("The Conjuring"); 
     nowShowing.add("Despicable Me 2"); 
     nowShowing.add("Turbo"); 
     nowShowing.add("Grown Ups 2"); 
     nowShowing.add("Red 2"); 
     nowShowing.add("The Wolverine"); 

     List<String> comingSoon = new ArrayList<String>(); 
     comingSoon.add("2 Guns"); 
     comingSoon.add("The Smurfs 2"); 
     comingSoon.add("The Spectacular Now"); 
     comingSoon.add("The Canyons"); 
     comingSoon.add("Europa Report"); 

     listDataChild.put(listDataHeader.get(0), top250); // Header, Child data 
     listDataChild.put(listDataHeader.get(1), nowShowing); 
     listDataChild.put(listDataHeader.get(2), comingSoon); 
    } 

     }; 

} 

答えて

0

以下の私のフラグメントのコードを配置しています要求を完了する前に、次のメソッドにジャンプします。私は2番目のメソッドload()を削除し、それを応答内に配置しました

関連する問題