Android RetroFit刷新列表

时间:2015-04-29 06:09:37

标签: android retrofit

我对RetroFit很新。当活动回到onResume时,我想刷新列表。场景是这样的,我在活动A中有列表(改造),然后用户点击将重定向到活动B的按钮。活动B关闭后,应刷新活动A中的列表。我怎样才能做到这一点?

这是我到目前为止所尝试的:

                RestAdapter restadapter = new RestAdapter.Builder()
                    .setEndpoint(Constants.URL_GET_ALL_RECORDS)
                    .setRequestInterceptor(requestInterceptor)
                    .setLogLevel(RestAdapter.LogLevel.FULL)
                    .build();

                RecordsAPI api = restadapter.create(RecordsAPI.class);
                api.getRecords(new Callback<List<Record>>() {
                    @Override
                    public void failure(RetrofitError arg0) {
                    }

                    @Override
                    public void success(List<Record> list, Response response) {

                        recordList = list;

                        recordadapter =
                                new DisplayAdapter(activity,
                                        R.layout.simple_spinner_item, recordList);

                        spinner.setAdapter(recordadapter);

                        if (recordadapter.getCount() == 0) {
                            lActionButtons.setVisibility(View.GONE);
                            layout.setVisibility(View.VISIBLE);
                            tvNotice.setText("No records found");

                            button.setOnClickListener(new OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    Intent i = new Intent(activity, ActivityB.class);
                                    activity.startActivity(i);
                                }
                            });

                        } else {
                            tvNotice.setVisibility(View.GONE);
                            spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
                                @Override
                                public void onItemSelected(AdapterView<?> parent, View v,
                                                           int pos, long id) {
                                }

                                @Override
                                public void onNothingSelected(AdapterView<?> parent) {
                                }
                            });

                        }


                    }
                });

任何想法如何刷新列表?我很乐意感谢任何帮助。谢谢!

0 个答案:

没有答案