EventBus 接收方法中死活不能执行UI更新,这有社么用呢
public class FragmentLeft extends Fragment {
public ListView lv;
LeftAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.text,
container, false);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
List<String> list = new ArrayList<String>();
list.add("111");
list.add("222");
list.add("33");
list.add("44");
EventBus.getDefault().post(list, "listTag");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
@Subscriber(tag = "listTag",mode = ThreadMode.MAIN)
private void getData(List<String> list) {
Log.i("mytag", "---- list = " +list.size());
adapter.setData(list);
adapter.notifyDataSetChanged();
//setListAdapter(new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,list));
}
@Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}
}
这 @Subscriber(tag = "listTag",mode = ThreadMode.MAIN)不是到UI线程了吗,list集合也有数据,但死活就是不走getViwe()