This example shares the specific code of Android using intent to pass parameters to implement multiplication calculations for your reference. The specific content is as follows
On the main interface are two EditTexts and a button. Used to enter two numerical parameters.
:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <EditText android: android:layout_height="wrap_content" android:layout_width="100dip" /> <TextView android:layout_width="50dip" android:layout_height="wrap_content" android:text="X" android:layout_marginLeft="30dip" /> <EditText android: android:layout_height="wrap_content" android:layout_width="100dip" /> </LinearLayout> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="calculate" /> </LinearLayout>
Java program that handles calcute
:
package ; import ; import ; import ; import ; import ; import ; import ; public class CaluteMain extends Activity { private EditText factory1; private EditText factory2; private Button calute; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub (savedInstanceState); setContentView(); factory1=(EditText)findViewById(.factory1); factory2=(EditText)findViewById(.factory2); calute=(Button)findViewById(); (new MyOnClickListener()); } class MyOnClickListener implements OnClickListener{ @Override public void onClick(View v) { String factoryStr1=().toString(); String factoryStr2=().toString(); Intent intent=new Intent(,); ("one", factoryStr1); ("two", factoryStr2); startActivity(intent); } } }
The interface of calculation results:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android: android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
Activity that receives two numerical parameters and displays the result. :
package ; import ; import ; import ; import ; public class CaluteResult extends Activity { private TextView resultView; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub (savedInstanceState); setContentView(); resultView=(TextView)findViewById(); Intent intent=getIntent(); String factoryStr1=("one"); String factoryStr2=("two"); //Convert string to shape int factoryInt1=(factoryStr1); int factoryInt2=(factoryStr2); int result=factoryInt1*factoryInt2; ("turn out:"+result+""); } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.