2017-12-19 1 views
-3

하나의 tabBase Activity과 하나의 Fragment이 있습니다. 기본 Activity의 API를 호출하고 해당 목록 데이터를 모델 목록 클래스를 사용하여 Fragment으로 전달합니다. 하지만 나는 항상 getlist 0을 얻고있다. pls 날 도와 줘요.목록 모델이 반환 목록을 가져 오지 않습니다.

public class ListTempStorage { 

    private List<MyPojoClassList> listOne = new ArrayList<>(); 
    private List<MyPojoClassList> listTwo = new ArrayList<>(); 
    private List<MyPojoClassList> listThree = new ArrayList<>(); 


    public List<MyPojoClassList> getListOne() { 
    return listOne; 
    } 
    public void setListOne(List<MyPojoClassList> listOne) { 
    this.listOne = listOne; 
    } 
    public List<MyPojoClassList> getListTwo() { 
    return listTwo; 
    } 

    public void setListTwo(List<MyPojoClassList> listTwo) { 
    this.listTwo = listTwo; 
    } 


} 

Fragment 클래스 :

public class MyFragment extends Fragment { 

    private ListTempStorage ourInstance; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.my_layout, container, false); 
    // Inflate the layout for this fragment 
    init(v); 

    return v; 
    } 
    private void init(View v) { 
    ourInstance= new ListTempStorage(); 

    try { 

      List<MyPojoClassList> list = ourInstance.getListOne(); 
      if (list != null && list.size() > 0) { 

       populateOpenAllLayout(list); 


     } catch (Exception e) { 
      if (OlabiConstant.IS_DEBUGGABLE) e.printStackTrace(); 
      activity.finish(); 

     } 
+0

제대로 들여 쓰기를하면 쉽게 읽을 수 있습니다. – khelwood

답변

1

으로 onCreateView에서 초기화를 호출 할 때 당신은 항상 당신의 데이터를 채울 수 있기 때문에 당신은 빈 얻을 것이다 :

private void init(View v) { 
    ourInstance= new ListTempStorage(); 
} 

당신은을 채울 필요 데이터를 가져온 다음 방법을 만듭니다.

public void populate(ListTempStorage tempStorage) { 
    ourInstance = tempStorage; 
    // update your data here. 
} 

그런 다음 기본 활동에서 메소드 조각을 호출 할 수 있습니다.

+0

내가 무슨 말을했는지 이해하지 못하고 있는데, 어디에서이 mehtod를 암시해야 하는가? – user8737536

+0

당신은 당신의 조각에 그것을 구현해야합니다. 그런 다음 프래그먼트가 호스팅되는 활동에서 호출하십시오. –

관련 문제