gpt4 book ai didi

java - 如何通过单击按钮将进度条设置为 'progress'?

转载 作者:行者123 更新时间:2023-12-01 10:31:51 25 4
gpt4 key购买 nike

我正在尝试创建一个按钮,单击该按钮将使进度条增加。

我已将栏设置为最大值 100,每次选择该按钮时,我希望它会上升 1/10。

有谁能帮忙解决这个问题吗?我的进度条就叫“progressBar”。

<ProgressBar
android:progressDrawable="@android:drawable/progress_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_above="@+id/imageView36"
android:max="100"
android:progress="10"
android:layout_alignEnd="@+id/btnGenerate"
android:layout_alignStart="@+id/btnGenerate" />





@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_squiz);

/*Button button =
(Button) findViewById(R.id.btnGenerate);
MyOnClickListener Listener =
new MyOnClickListener();
button.setOnClickListener((View.OnClickListener) Listener);*/


//btnGenerate = (Button) findViewById(R.id.btnGenerate);
//btnGenerate.setOnClickListener(btnGenerateListener);
TextView ABshow = (TextView) findViewById(R.id.ABNumber);
TextView BCshow = (TextView) findViewById(R.id.BCNumber);
TextView Ashow = (TextView) findViewById(R.id.ANumber);
// btnRand.setOnClickListener(btnRandListener);
Random rnd = new Random();
int ABrandomNumber = rnd.nextInt(34) + 5; //random number between 5 and 39
//Toast.makeText(SineQuiz.this, "Rand num: " + String.valueOf(ABrandomNumber), Toast.LENGTH_SHORT).show();
ABshow.setText("" + String.valueOf(ABrandomNumber));
int BCrandomNumber = rnd.nextInt(20) + 5; //random number between 5 and 25
//Toast.makeText(SineQuiz.this, "Rand num: " + String.valueOf(BCrandomNumber), Toast.LENGTH_SHORT).show();
BCshow.setText("" + String.valueOf(BCrandomNumber));
int ArandomNumber = rnd.nextInt(25) + 5; //random number between 5 and 30
//Toast.makeText(SineQuiz.this, "Rand num: " + String.valueOf(ArandomNumber), Toast.LENGTH_SHORT).show();
Ashow.setText("" + String.valueOf(ArandomNumber));

/* button.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {

progressBar.setProgress(progressBar.getProgress() + 10);
}
});*/


}



public void setBtnGenerateListener (View view) {
progressBar.setProgress(progressBar.getProgress() + 10);}
/*public View.OnClickListener btnGenerateListener = new View.OnClickListener() {
@Override

public void onClick(View v) {
progressBar.setProgress(progressBar.getProgress() + 10);
}
};*/

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_sine_quiz, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);

}

抱歉,我不知道代码是否有很大帮助!理想情况下,如果这个按钮也可以生成我上面的随机数,那就太好了!

最佳答案

只需将进度设置为进度条即可:

progressBar.setProgress(progressBar.getProgress()+10);

将其放入您的点击事件中:

myButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
progressBar.setProgress(progressBar.getProgress()+10);
}
});

关于java - 如何通过单击按钮将进度条设置为 'progress'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35046809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com