Fragment中的ListView中没有数据显示。它会在滚动时显示

时间:2016-04-26 04:57:30

标签: android

这是我的第一个片段......这里的问题是什么我在这个片段数据中有四个片段bt只显示我的研究它...基本上我在这个活动中有四个标签reamainig三个工作正常。在第一个片段我使用网络服务

public class Home_Fr extends ListFragment {

    int a;
    int i=0;
    String[][] radioname;
    String[][] radio_id;
    String[][] radio_img;
    String[] catname;

    ListView lv;


    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {

        View frag= inflater.inflate(R.layout.home_fr, container, false);
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        String name = preferences.getString("categories_id", "");
        String[] cat_id=name.split("-");
        Log.d("ye id milli ya ni",cat_id[0]);

        radioname=new String[cat_id.length][3];
        radio_img=new String[cat_id.length][3];
        catname=new String[cat_id.length];
        radio_id=new String[cat_id.length][3];
        for(a=0;a<cat_id.length;a++)
        {
            getdata(cat_id[a], a);
        }


        lv= (ListView)frag.findViewById(android.R.id.list);

        lv.setAdapter(new HomeFr_listAdepter(getActivity(), catname, radioname, radio_img, radio_id));

        return frag;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onActivityCreated(savedInstanceState);




    }


    private void getdata(String k, final int l) {

        final ProgressDialog loading = ProgressDialog.show(getActivity(), "Fetching Data", "Please wait...", false, false);
        RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint("http://api.dirble.com/v2/category/"+k)
                .build();

        RadioListApi api = adapter.create(RadioListApi.class);
        api.getCategories_id(new Callback<List<RadioListModel>>() {
            @Override
            public void success(final List<RadioListModel> list, Response response) {
                loading.dismiss();
                catname[l]=list.get(0).getName();
                for (int j = 0; j < 3; j++) {

                    ImageModel im = list.get(j).getImage();
                    radio_img[l][j] = im.getUrl();
                    radioname[l][j] = list.get(j).getName();
                    radio_id[l][j] = list.get(j).getId();
                }

            }

            @Override
            public void failure(RetrofitError error) {
                //you can handle the errors here
            }
        });

    }
}

1 个答案:

答案 0 :(得分:0)

您忘记在服务响应的success方法中添加notifyDataSetChange。

如果适配器不为null,请尝试在success方法中编写notifyDataSetChange。