0
UI를 편집하기 위해 runOnUiThread를 시작하는 새 스레드를 시작하기 위해 목록보기를 3 초마다 새로 고쳐야합니다 (ListFragment에 있음).BaseAdapter notifyDataSetChanged()가 객체 참조를 업데이트하지 않습니다.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
new Thread(new Runnable() {
public void run() {
do{
ObjectMapper mapper = new ObjectMapper();
VideoData element = null;
try {
element = mapper.readValue(new URL("http://192.168.4.111:3232/videodata.json").openStream(), VideoData.class);
} catch (Exception e) {
e.printStackTrace();
}
final VideoData newData = element;
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
hd = newData.getChildren().get(0).getChildren().get(id);
vba.notifyDataSetChanged();
}
});
try {
Thread.sleep(3*1000);
} catch (InterruptedException e) {}
}while(true);
}
}).start();
setAdapter();
}
웹상의 데이터를 구문 분석하고 참조를 업데이트하십시오.
private void setAdapter()
{
if(id == 0)
hd = hd.getChildren().get(0);
vba = new ValueBaseAdapter(getActivity(), 0, hd.getChildren());
setListAdapter(vba);
}
내가 notifyDataSetChanged를 호출 할 때,의 getView가 호출 (그것은 괜찮습니다)하지만 난 오래된 참조가 것을보고, 내가는, setAdapter 처음 전화했을 때의 일. 또한 run()에 null hd를 설정하면 아무 것도 변경되지 않고 listview는 변경되지 않습니다. 어디서 오류가 있습니까? 감사.