我试图让 ProgressDialog 在显示它之前加载我的列表视图,但我遇到了崩溃。会有更好的方法来实现这一点吗?
编辑:更新了 logcat 错误,忘记了它。
List<String> internetArray = new ArrayList<String>();
private ProgressDialog p;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView internetList = (ListView)findViewById(R.id.list);
p = ProgressDialog.show(this, "Please wait..", "Loading list..", true);
new Thread(){
public void run(){
//do some extreme work before creating list
try {
sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
internetArray.clear();
//p.dismiss();
}
}.start();
getPermissions(this);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, internetArray);
arrayAdapter.sort(new Comparator<String>() {
public int compare(String object1, String object2) {
return object1.compareTo(object2);
};
});
internetList.setAdapter(arrayAdapter);
}