2017-09-20 3 views
0

조각과 okhttpp 클라이언트가 있습니다. 조각 내에서 요청을하면 okhttp는 내 응답에 mProgressBar.setVisibility(View.GONE);을 설정하고 200 응답 ID를받습니다. 하지만 불행히도 아무 일도 일어나지 않습니다. 나는 응답을 얻고 코드는 mProgressBar.setVisibility(View.GONE);이지만 아무 일도 일어나지 않지만 mProgressBar는 여전히 표시되지만 로그는 mProgressBar not visible으로 표시됩니다. 왜 그렇습니까?조각`보기를 다른 스레드로 수정하는 방법?

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
{ 
    View rootView = inflater.inflate(R.layout.fragment_shemas, container, false); 
    ls = (Ls) getActivity().getApplicationContext(); 
    mProgressBar = rootView.findViewById(R.id.pb_fr_schema); 

    mClient = ls.createClient(getActivity()); 
    Log.d(TAG, "Назначили OkHttpClient " + mClient.toString() + " для " + this.getClass().toString() + " в " + this.getClass().toString()); 

    try 
    { 
     String url = ls.baseUrl + ls.getLsId() + "/" + ls.getCurrBidId() + "/call-fwd-settings/overview"; 
     requestOkHttp(url, "GET", ""); 
    } catch (IOException e) 
    { 
     e.printStackTrace(); 
    } 

    mSpinner = (Spinner) rootView.findViewById(R.id.sp_fr_schemas_did); 
    // Список номеров 
    ArrayList<String> didsNames = new ArrayList<>(); 
    for (Map.Entry<String, Bid> pr : ls.getProducts().entrySet()) 
    { 
     didsNames.add(pr.getValue().getBidName()); 
    } 

    mAdapter = new ArrayAdapter<String>(getActivity(), R.layout.spinner_row_products, R.id.tv_bid_name, didsNames); 
    // Чтобы был читаемый дизайн при выборе DID 
    mAdapter.setDropDownViewResource(R.layout.spinner_row_products); 
    //spinner.setAdapter(mAdapter); 
    return inflater.inflate(R.layout.fragment_shemas, container, false); 
} 

는 여기에 내가 해결책을 발견 okhttp 응답 코드

getActivity().runOnUiThread(new Runnable(){ 
@Override 
public void run(){ 
// Отключаем mProgressBar 
mProgressBar.setVisibility(View.GONE); 
if (mProgressBar.getVisibility() == View.VISIBLE) { 
Log.d(TAG, " mProgressBar visible"); 
} else { 
Log.d(TAG, " mProgressBar not visible"); 
} 
} 
}); 

답변

0

에게 있습니다. 문제가 return에있었습니다. 이 부분을 return inflater.inflate(R.layout.fragment_shemas, container, false);으로 변경하면 return rootView;으로 바뀌 었습니다.