2016-08-29 2 views
-2

JSON 데이터를 ListFragment로 비동기 적으로로드하는 데 loopj를 사용하고 있습니다. ListFragment 함께 제공되는 기본 listview 및 loopj의 OnSuccess 콜백 함수 내 메서드 FillListView 호출 사용하고 있습니다. 나는이 문제에 관한 많은 비슷한 게시물을 둘러 보았지만 나의 문제를 해결할 수는 없다. ListFragment가 비동기 데이터를 표시하지 않습니다.

는 또한

MenuCatFragment.newInstance("a","c").setListAdapter(adapter); 

를 호출하여 MainActivity에서 ListFragment를로드 시도했지만이 역시 작동하지 않습니다.

아무도 도와 줄 수 있습니까?

public class MenuCatFragment extends ListFragment {
  

//android studio auto-generated code ommitted  

public MenuCatFragment() { }
  


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if (getArguments() != null) { 
     mParam1 = getArguments().getString(ARG_PARAM1); 
     mParam2 = getArguments().getString(ARG_PARAM2); 
    } 

    myApp = (App)this.getActivity().getApplication(); 
    currentRestoSummary = myApp.getSelectedRestoSummary(); 
    restoid = currentRestoSummary.getRestoid(); 

try { 
     LoadSelectedResto(); 
    } catch (Exception e) { 
    } 

} 

private void LoadSelectedResto() throws JSONException { 


    EatNowRestClient.get("resto", new RequestParams("id", restoid), new JsonHttpResponseHandler() { 


     @Override 
     public void onSuccess(int statusCode, Header[] headers, JSONObject response) { 

      Gson gson = new Gson(); 
      Type listType = new TypeToken<Resto>() {}.getType(); 

      try { 
       resto = gson.fromJson(response.toString(), listType); 

       myApp.setSelectedResto(resto); 

       FillListView(); 

       //progressDialog.dismiss(); 


      } catch (Exception e) { 

       throw e; 
      } 
     } 


     @Override 
     public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { 
      super.onFailure(statusCode, headers, throwable, errorResponse); 
      //progressDialog.dismiss(); 
      //Log.d("Failed: ", ""+statusCode); 
      //Log.d("Error : ", "" + throwable); 
     } 

    }); 

private void FillListView() { 

ListAdapter adapter; 

adapter = new customAdapterMenuCat(getActivity(),R.layout.custom_row_menucat,resto.getMenu_Categories()); 

setListAdapter(adapter); 

    } 


} 

//adapter code 

public class customAdapterMenuCat extends ArrayAdapter<MenuCategory> { 

MenuCategory[] menucat; 
Context c; 

public customAdapterMenuCat(Context context, int resource, MenuCategory[] objects) { 
    super(context, resource, objects); 

    menucat = objects; 
    c = context; 
} 

@Override 
public int getCount() { 
    return menucat.length; 
} 

@Override 
public MenuCategory getItem(int position) { 
    return menucat[position]; 
} 

@Override 
public long getItemId(int position) { 
    return position; 
} 

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    View customview = View.inflate(c, R.layout.custom_row_menucat,null); 

    TextView lblMenuCatNameResto = (TextView)customview.findViewById(R.id.lblMenuCat); 

    lblMenuCatNameResto.setText(menucat[position].getName()); 

    return customview; 


} 

}

+0

LoadSelectedResto() 메소드에 대한 호출이 없습니다. –

+0

죄송합니다 ... 방금 붙여 넣었습니다. OnCreate() 메소드에 있습니다. –

+0

'어댑터'코드를 입력하십시오. 이 문제는 여기에있을 가능성이 큽니다. –

답변

0

나는 아래의 작업 중 하나입니다 ... 문제는 fragmenttabhost 레이아웃 XML을했다 ... 해결책을 발견했다.

<android.support.v4.app.FragmentTabHost 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/tabResto"> 

    <FrameLayout 
     android:id="@android:id/tabcontent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom"/> 

     <FrameLayout 
      android:id="@+id/realtabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 

    </LinearLayout> 
</android.support.v4.app.FragmentTabHost> 
관련 문제