我遇到这个问题,如果我在片段之间切换就可以。但是当我从另一个活动退出时,它不会刷新。
我对此有点弱,如果可能,请说明在哪里添加代码,谢谢你' ll
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.favorite_page, null);
lv = (ListView) view.findViewById(R.id.listview_favorite);
list = new ArrayList<>();
adapter = new BaseAdapter() {
...
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(getActivity());
...
convertView = tv;
return convertView;
}
};
lv.setAdapter(adapter);
List<FavoriteBean> favData = DataSupport.findAll(FavoriteBean.class);
InputStream inputStream = getResources().openRawResource(R.raw.a);
try {
JSONObject obj = new JSONObject(LoadFiles.getString(inputStream));
JSONArray jarry = obj.getJSONArray("items");
...
} catch (JSONException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
尝试:
((BaseAdapter)lv.getAdapter()).notifyDatasetChanged();
答案 1 :(得分:0)
使用adapter.notifyDataSetChanged();