Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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:-





Java
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);
		             
		    }
       });
      }
     

    
		
		
	}
Posted
Updated 27-Jan-14 2:11am
v2

1 solution

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
 
Share this answer
 
v2
Comments
chandan kumar 28-Jan-14 1:31am    
Hello!!! i wanted to multiplication table number one by one..with some time that's why i used delay.I tried with thread but i am not succeeded can you help with some code i am grateful for that.

Thank's
Chandan Kumar
Aravindba 28-Jan-14 1:34am    
pls increase delay time,only thread we have to deleay the code execute,increase sleep(10) like that.
why without time it multiplicative the table one by one,u need first multiplication answer for second table multiplicative ?so without first answer code passed to second table multiplication ?
chandan kumar 28-Jan-14 1:40am    
i used before but it doesn't changed anything.what i was getting after sleep it delay start of my table..but i wanted some time between my table.Like 2delay *delay 2delay =delay 4delay .Hope i am able to understand my point.
Aravindba 28-Jan-14 1:49am    
u need to increase the delay time in each table ?if yes means,just declare one global variable as in integer,if code execute change the variable values like,variable is i = 2;
then first table codes execute i=i*2 ,if second table codes executes i=i*2 like that.
by default i=2,if 1st table execute i change to 4,then 8 ...

use delay method inside of table code,not in whole function.
chandan kumar 28-Jan-14 1:56am    
yes i wanted to delay in table between number in multiplication table.i am trying to get number with the help of button click when someone press 1 then it gets data from button then it goes to second activity then it function on table.where i wanted to delay in between my table .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900