无论我尝试什么,我都无法让我的进度条工作。这是代码:
public void setDayView(final int _day, final int _month, final int _year) {
ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar);
progressBar.setVisibility(ProgressBar.VISIBLE);
comm = new Thread() {
public void run() {
final postRequest req = new postRequest(username, password);
doc = (Document) req.GetDayEvents(_day, _month, _year);
}
};
comm.start();
while (comm.isAlive()) { // waiting for network to finish
}
progressBar.setVisibility(ProgressBar.GONE);
NodeList eventsTitles = doc.getElementsByTagName("Title");
NodeList eventsClasses = doc.getElementsByTagName("Class");
NodeList eventsTypes = doc.getElementsByTagName("Type");
NodeList eventsComments = doc.getElementsByTagName("Comment");
NodeList eventsAmounts = doc.getElementsByTagName("Amount");
NodeList eventsHashes = doc.getElementsByTagName("Hash");
NodeList refCurrency = doc.getElementsByTagName("RefCurrency");
NodeList dateStamp = doc.getElementsByTagName("DateStamp");
final int nrOfEvents = eventsTitles.getLength();
LinearLayout dayEventsArea = (LinearLayout) findViewById(R.id.DayEventsArea);
// set SelectedDayLabel
TextView selDayLabel = (TextView) findViewById(R.id.selectedDayLabel);
selDayLabel.setText(dateStamp.item(0).getTextContent());
//
// set day totals labels
TextView dayDebit = (TextView) findViewById(R.id.dayDebitLabel);
TextView dayOutgo = (TextView) findViewById(R.id.dayOutgoLabel);
TextView dayIncome = (TextView) findViewById(R.id.dayIncomeLabel);
dayDebit.setText("Debit: "
+ doc.getElementsByTagName("DayDebit").item(0).getTextContent()
+ " " + refCurrency.item(0).getTextContent());
dayOutgo.setText("Outgo: "
+ doc.getElementsByTagName("DayOutgo").item(0).getTextContent()
+ " " + refCurrency.item(0).getTextContent());
dayIncome.setText("Income: "
+ doc.getElementsByTagName("DayIncome").item(0)
.getTextContent() + " "
+ refCurrency.item(0).getTextContent());
//
dayEventsArea.removeAllViews();
// clearing all local caches
_eventsTitlesLocalCopy.clear();
_eventsClassesLocalCopy.clear();
_eventsAmountsLocalCopy.clear();
_eventsCommentsLocalCopy.clear();
_eventsTypesLocalCopy.clear();
_eventsHashesLocalCopy.clear();
//
for (int i = 0; i < eventsTitles.getLength(); i++) {
// creating a local cache of the day events, as they can be edited
// and sent back
_eventsTitlesLocalCopy.add(eventsTitles.item(i).getTextContent());
_eventsClassesLocalCopy.add(eventsClasses.item(i).getTextContent());
_eventsAmountsLocalCopy.add(eventsAmounts.item(i).getTextContent());
_eventsCommentsLocalCopy.add(eventsComments.item(i)
.getTextContent());
_eventsTypesLocalCopy.add(eventsTypes.item(i).getTextContent());
_eventsHashesLocalCopy.add(eventsHashes.item(i).getTextContent());
//
和 layout.xml 中的代码
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="center" />
如果我关闭代码行 progressBar.setVisibility(ProgressBar.GONE); 然后我的进度条一直显示,所以它确实有效。