如何延迟android中乘法表中的每个数字? [英] how to delay on each number in multiplication table in android?
本文介绍了如何延迟android中乘法表中的每个数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在乘法数之间延迟,但我只能逐行延迟
这是我的乘法代码表: -
MainActivity.java
i am trying to delay between multiplication number but i am only able to delay line by line
Here is My code of multiplication Table:-
MainActivity.java
public class MainActivity extends Activity {
TextView txtView;
int value,keyvalue = 0;
static int count = 0;
StringBuilder sb = new StringBuilder();
Handler handle = new Handler();
Runnable r = new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "onrunnable" +sb, 222).show();
// TODO Auto-generated method stub
updateTable();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent i = getIntent();
String someVariable = i.getStringExtra("MA");
Toast.makeText(getApplicationContext(), "SomeVariable" +someVariable, 222).show();
keyvalue = Integer.parseInt(someVariable);
txtView = (TextView) findViewById(R.id.outputTXT);
updateTable();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void updateTable(){
count+=1000;
if(count==11000){
//Toast.makeText(getApplicationContext(), "onupdate" , 222).show();
count = 0;
keyvalue=0;
handle.removeCallbacks(r);
sb.setLength(0);
}else{
sb.append(keyvalue + " x " + count/1000 + " = " + count/1000 * keyvalue+ "\n");
handle.postDelayed(r, 1000);
Toast.makeText(getApplicationContext(), "onupdateElse" +sb, 222).show();
txtView.setText(sb);
}
}
}
TestActivity: -
TestActivity:-
public class TestActivity extends Activity{
Button tableButton1,tableButton2;
String s;
int value = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text_display);
Toast.makeText(getApplicationContext(), "oncreate" , 222).show();
tableButton1 = (Button) findViewById(R.id.seven);
tableButton1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Toast.makeText(getApplicationContext(), "onclick" , 222).show();
value= Integer.parseInt(tableButton1.getText().toString());
Toast.makeText(getApplicationContext(), "onclick" +value, 222).show();
s=String.valueOf(value);
Toast.makeText(getApplicationContext(), "onclickS" +s, 222).show();
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
intent.putExtra("MA", s);
startActivity(intent);
}
});
tableButton2 = (Button) findViewById(R.id.eight);
tableButton2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Toast.makeText(getApplicationContext(), "onclick" , 222).show();
value= Integer.parseInt(tableButton2.getText().toString());
Toast.makeText(getApplicationContext(), "onclick" +value, 222).show();
s=String.valueOf(value);
Toast.makeText(getApplicationContext(), "onclickS" +s, 222).show();
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
intent.putExtra("MA", s);
startActivity(intent);
}
});
}
}
推荐答案
Hi
为什么你需要延迟?任何操作都没有完成。我的意思是代码在乘法表之前快速执行,只需使用sleep方法,sleep(5000)5秒,添加线程namespace.i有这样的问题,在数据库中添加数据之前,代码传递代码,所以我用睡眠方法来延迟代码执行。
问候
Aravind
Hi Why u need delay ? any operation not finish.i mean code execute quickly before multiplication table,simply use sleep method,sleep(5000) for 5 secs,add threading namespace.i have face problem like this,before add data in database,the code pass the code, so i use sleep method to delay the codes executes.
Regards
Aravind
这篇关于如何延迟android中乘法表中的每个数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文