Android에서 진행률 표시 줄을 만들었지 만 전혀 작동하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 나는 안드로이드를 배우기 시작했습니다. 아래는 제 코드입니다.Android 진행률 막대가 작동하지 않습니다.
MainActivity.java-
public class MainActivity extends AppCompatActivity {
ProgressBar progressBar;
int mporgress=0;
EditText time;
private Handler mHandler = new Handler();
private static final int PROGRESS = 0x1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Startbuttononclick(View view){
Button startbutton=(Button) findViewById(R.id.button);
startbutton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
mporgress = Integer.parseInt(time.getText().toString());
progressBar.setProgress(mporgress);
new Thread(new Runnable() {
public void run() {
while (mporgress < 100) {
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(mporgress);
mporgress = doWork();
try{
Thread.sleep(1000);
}catch (InterruptedException e){}
}
});
}
}
}).start();
}
});
}
public void doprogress(View view) {
}
public int doWork(){
mporgress++;
return mporgress;
}
}
Activity_main.xml-이
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.progressbar.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the time:"
android:inputType="number"
android:id="@+id/editText" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="500dp"
android:layout_height="200dp"
android:id="@+id/progressBar4"
android:layout_gravity="center"
android:scrollbarSize="500dp" />
<Button
android:text="START"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_gravity="center"
android:onClick="Startbuttononclick" />
</LinearLayout>
체크 아웃 below-이 이미지 - https://i.stack.imgur.com/2TBIb.png
을이 이미지에 시간을 입력 참고 -은 글고입니다 TextView가 아니라 힌트가 있습니다.
표시되지만 작동하지 않습니다.
https://i.stack.imgur.com/UujpB.png
그리 멀지하지만 여전히 진행 표시 줄이 여전히 계속 회전하고 그래서 이러한 변경을 수행했다.
"전혀 일"정의합니다. 전혀 표시하지 않습니까? 업데이트하지 않습니까? 완전히 다른 것? –
@GabeSechan 질문을 업데이트했습니다. 검토하십시오. – Knattic
MainThread에서 잠을 자고 있다고 생각하기 때문에 생각합니다. 수면 호출을 외부 스레드로 이동해보십시오. –