我有一个自定义进度条,基本上当我输入一个值然后按一个按钮时,我想要更新进度条。我的进度条基本上只有三个值,可以是0%,33%,66%或100%。出于某种原因,当我进入带有进度条的页面,甚至在TextView中输入值然后输入按钮时,它只是显示一个加载圈,因为某些原因永远不会结束。我已经发布了进度条所需的所有代码,所以有人知道为什么它没有显示正确的进度条以及它为什么只显示加载圈?
custom_progressBar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="#000001"
android:centerColor="#0b131e"
android:centerY="1.0"
android:endColor="#0d1522"
android:angle="270"
/>
</shape>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#007A00"
android:centerColor="#007A00"
android:centerY="1.0"
android:endColor="#06101d"
android:angle="270"
/>
</shape>
</clip>
</item>
progressBarShirts.java
package ankitkaushal.app.healthysizing;
import android.graphics.drawable.Drawable;
import android.sax.TextElementListener;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class progressBarShirts extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress_bar_shirts);
final DatabaseHelper db = new DatabaseHelper(this);
final TextView currentSizeDisplay = (TextView) findViewById(R.id.currentSizeShirts);
Button enterNewSizeButton = (Button) findViewById(R.id.newSizeEnterButtonShirts);
final EditText newSize = (EditText) findViewById(R.id.newSizeShirts);
final String currentSize = db.getCurrentShirtSize();
currentSizeDisplay.setText("Your current size: " + currentSize);
Drawable draw = getResources().getDrawable(R.drawable.custom_progressbar);
enterNewSizeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String size = newSize.getText().toString().toUpperCase();
currentSizeDisplay.setText("Your current size: " + size);
db.updateSizeShirts(size);
}
});
ProgressBar shirts = (ProgressBar) findViewById(R.id.progressBarShirts);
shirts.setProgressDrawable(draw);
String startSize = db.getStartSizeShirts();
String newCurrentSize = db.getCurrentShirtSize();
String limit = db.getLimit("setLimitShirts");
shirts.setMax(100);
if (startSize.equals("XL") && limit.equals("S")) {
if (newCurrentSize.equals("L")) {
// Fill progress bar by 1/3
shirts.setProgress(33);
}
if (newCurrentSize.equals("M")) {
// Fill progress bar by 2/3
shirts.setProgress(66);
}
if (newCurrentSize.equals("S")) {
// Fill progress bar 100 percent
shirts.setProgress(100);
// Give a toast saying you've reached your limit
Toast.makeText(this, "You've reached your limit! ", Toast.LENGTH_LONG).show();
// Set all values in database to null
db.removeLImit("setLimitShirts");
}
}
}
}
activity_progress_bar_shirts.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#29A9D2"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Track your progress"
android:id="@+id/TrackProgressShirts"
android:layout_gravity="center_horizontal"
android:textColor="#FFFFFF"
android:textSize="30dp"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Current Size: Large"
android:id="@+id/currentSizeShirts"
android:layout_gravity="center_horizontal"
android:textSize="30dp"
android:layout_marginTop="80dp"
android:textColor="#FFFFFF" />
<EditText
android:layout_width="350dp"
android:layout_height="wrap_content"
android:id="@+id/newSizeShirts"
android:layout_marginTop="20dp"
android:hint="Enter your new size"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textSize="30dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter new size"
android:id="@+id/newSizeEnterButtonShirts"
android:layout_gravity="center_horizontal" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="300dp"
android:progressDrawable="@drawable/custom_progressbar"
android:layout_height="wrap_content"
android:id="@+id/progressBarShirts"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginTop="170dp"
android:max="100"
android:minWidth="300dp"
android:minHeight="100dp"
android:maxWidth="300dp"
android:maxHeight="100dp"
android:indeterminateOnly="true"
android:progress="0" />
</LinearLayout>