我正在尝试创建一个按钮,单击该按钮会使进度条增加。
我已将条设置为最大值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);
}
抱歉,我不知道代码是否有很多帮助!理想情况下,如果此按钮也可以生成我上面的随机数,那将是一个奖励!
答案 0 :(得分:2)
只需将进度设置为progressBar:
progressBar.setProgress(progressBar.getProgress()+10);
将其置于点击事件中:
myButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
progressBar.setProgress(progressBar.getProgress()+10);
}
});
答案 1 :(得分:-1)
在按钮的点击监听器中添加此项。
using System;
using System.Globalization;
public class PrintCurrencyValue {
public static void Main() {
double x = 12.5;
RegionInfo myRI1 = new RegionInfo( "ar-EG" );
Console.WriteLine( "CurrencySymbol: {0} {1:N}", myRI1.CurrencySymbol, x);
Console.WriteLine( "ISOCurrencySymbol: {0} {1:N}", myRI1.ISOCurrencySymbol, x);
}
}