1. 主线程可以直接调用Invalidate()方法刷新。
2. 子线程可以直接调用postInvalidate()方法刷新。
API的描述是这样的 :?Invalidatethe whole view. If the view is visible, onDraw(Canvas) will be called at somepoint in the future. This must be called from a UI thread. To call from anon-UI thread, call postInvalidate().。当Invalidate()被调用的时候,View的OnDraw()就会被调用,Invalidate()必须是在UI线程中被调用,如果在新线程中更新视图的就调用postInvalidate()。
1、adpter.notifyDataSetChanged();
2、例子
public class TestActivity extends Activity {
private ListView listView;
private MyAdapter myAdapter;
private List<>
public Context context;
private String[] from = new String[] { "color", "name" };
private int[] to = new int[] { R.id.color,R.id.name };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_select_layout);
datas = new ArrayList<>
myAdapter = new MyAdapter(context);
listView.setAdapter(myAdapter);
}
public void setDatas(String str){
// String str = "[{\"color\":\"#3EA2FF\",\"name\":\"居民楼\"},{\"color\":\"#FCF1CA\",\"name\":\"商业楼\"},{\"color\":\"#D8424F\",\"name\":\"单位院\"}]";
LayoutInflater mInflater = LayoutInflater.from(context);
View view = mInflate...
1、adpter.notifyDataSetChanged();
2、例子
public class TestActivity extends Activity {
private ListView listView;
private MyAdapter myAdapter;
private List<>
public Context context;
private String[] from = new String[] { "color", "name" };
private int[] to = new int[] { R.id.color,R.id.name };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_select_layout);
datas = new ArrayList<>
myAdapter = new MyAdapter(context);
listView.setAdapter(myAdapter);
}
public void setDatas(String str){
// String str = "[{\"color\":\"#3EA2FF\",\"name\":\"居民楼\"},{\"color\":\"#FCF1CA\",\"name\":\"商业楼\"},{\"color\":\"#D8424F\",\"name\":\"单位院\"}]";
LayoutInflater mInflater = LayoutInflater.from(context);
View view = mInflater.inflate(R.layout.legend_item, null);
if (!