我想在不同的線程中獲取谷歌日曆名稱後更新微調對象。當我執行這個時,它崩潰。我不確定是否需要使用不同的方法進行工作,或者如果有什麼問題。android - 更新進度條
private void updateGoogleCalendar() {
try {
Thread.sleep(4000);
List<String> list = new ArrayList<String>();
list.add("Sample Calendar");
updatedCalendarNames = list.toArray(new String[0]);
progressBar.dismiss();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void initializeWidgets() {
final Spinner spinner = (Spinner) layout.findViewById(R.id.googleCalendarSelection);
final Button refreshCalendarBtn = (Button) layout.findViewById(R.id.refreshCalendarBtn);
refreshCalendarBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
progressBar = ProgressDialog.show(getContext(), "", "Loading...");
new Thread(new Runnable() {
@Override
public void run() {
updateGoogleCalendar();
final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(), android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
while (updatedCalendarNames == null) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
for (String calendarName : updatedCalendarNames) {
CharSequence charSequence = calendarName + "";
adapter.add(charSequence);
}
}
}).start();
}
});
}
你能顯示logcat輸出? – bluefalcon 2012-02-03 04:24:33