Click here to Skip to main content
14,208,441 members
Rate this:
 
Please Sign up or sign in to 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

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





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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
   
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 .
Aravindba 28-Jan-14 2:10am
   
delay after user button click,or delay after data get from db
chandan kumar 28-Jan-14 2:24am
   
i am not getting any data from db. its getting data after click on button.
Aravindba 28-Jan-14 5:04am
   
i am not understand ur problem,why u need delay,if without delay time u can multiplication table number one by one ? what in this problem ? code executes line by line,in above code where u delay and not work ?
chandan kumar 28-Jan-14 5:18am
   
its basic learning table for kid.so i have to show with delay.
Aravindba 28-Jan-14 5:33am
   
if user click button then only multiply with next number ? u have to modify the code like,u put one arrow button,if user click arrow button then multiply with next number,no need delay,bcz user click event it multiply...in button click event u have to increment the count,that count uis used to multiply.if reach 10 ,then go to next multiply table
chandan kumar 28-Jan-14 6:15am
   
okay..can you send or share some code and screen.so i can understand how to get it.
Aravindba 29-Jan-14 1:13am
   
actually if u multiply last answer only show ? if 1x1=1,1x2=2,1x3=3.....1x10=10.
u need to show each answer,but now show quickly to last answer i.e 1x10=10 ?

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



Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190612.1 | Last Updated 28 Jan 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100