Lecture 6: Development For Mobile Development PDF

Document Details

RefreshedForesight994

Uploaded by RefreshedForesight994

Egyptian Russian University

Assoc. Prof. Mina Ibrahim

Tags

android development java programming mobile applications software development

Summary

This document is a lecture on mobile software development, specifically focusing on Android development with Java and XML. The lecture discusses various aspects of creating Android applications, including user interface design elements (like buttons and text input), performing calculations with input values, displaying results, using alerts, and launching external applications or websites.

Full Transcript

Development for Mobile Lecture 6 Assoc. Prof. Mina Ibrahim activity_main2.xml MainActivity2.java Define button b4 (id button4), button b5 (id button5), plain text t1 (id txtName), plain text t2 (id txtAddress) and text view (id resview): public class MainActivity...

Development for Mobile Lecture 6 Assoc. Prof. Mina Ibrahim activity_main2.xml MainActivity2.java Define button b4 (id button4), button b5 (id button5), plain text t1 (id txtName), plain text t2 (id txtAddress) and text view (id resview): public class MainActivity2 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); Button b4 = (Button) findViewById(R.id.button4); Button b5 = (Button) findViewById(R.id.button5); EditText t1 = (EditText) findViewById(R.id.txtName); EditText t2 = (EditText) findViewById(R.id.txtAddress); TextView Res=(TextView)findViewById(R.id.resview); b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ……….. } }); MainActivity2.java onClick function to display plain text t1 for long time then disappear automatically : b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity2.this,t1.getText().toString(), Toast.LENGTH_LONG).show(); } }); MainActivity2.java onClick function to display plain text t1 in text view Res: b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Res.setText(t1.getText().toString()); } }); MainActivity2.java onClick function to add two numbers which are entered in plain text t1 and t2 then display the result in text view Res : b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { double num1, num2, num3; num1 = Double.parseDouble(t1.getText().toString()); num2 = Double.parseDouble(t2.getText().toString()); num3=num1+num2; Res.setText(Double.toString(num3)); } }); MainActivity2.java onClick function to subtract two numbers which are entered in plain text t1 and t2 then display the result in text view Res : b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { double num1, num2, num3; num1 = Double.parseDouble(t1.getText().toString()); num2 = Double.parseDouble(t2.getText().toString()); num3=num1-num2; Res.setText(Double.toString(num3)); } }); MainActivity2.java onClick function to create and display alert dialog: b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder d = new AlertDialog.Builder(MainActivity2.this); d.setTitle("hi"); d.setMessage("hello"); Title Message d.setPositiveButton("add", null); d.setNegativeButton("sub", null); d.show(); } }); Negative Positive button button MainActivity2.java onClick function to create and display alert dialog with two functions: b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder d = new AlertDialog.Builder(MainActivity2.this); d.setTitle("hi"); d.setMessage("hello"); d.setPositiveButton("add", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { double num1, num2, num3; num1 = Double.parseDouble(t1.getText().toString()); num2 = Double.parseDouble(t2.getText().toString()); num3=num1+num2; Res.setText(Double.toString(num3)); } }); MainActivity2.java d.setNegativeButton("sub", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { double num1, num2, num3; num1 = Double.parseDouble(t1.getText().toString()); num2 = Double.parseDouble(t2.getText().toString()); num3=num1-num2; Res.setText(Double.toString(num3)); } }); d.show(); } }); MainActivity2.java onClick function to go to a web site which is entered in plain text t1: b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i=new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(t1.getText().toString())); //URL of web site startActivity(i); } }); MainActivity2.java onClick function to dial a number which is entered in plain text t1: b4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i=new Intent(Intent.ACTION_DIAL); i.setData(Uri.parse("tel:"+t1.getText().toString())); startActivity(i); } }); ListView activity_third.xml …… ……. ThirdActivity.java public class ThirdActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_third); ListView lView=(ListView) findViewById(R.id.listItem1); String [] s={"01200000000","01000000000","01100000000","01500000000"}; ArrayAdapter arr=new ArrayAdapter(ThirdActivity.this, android.R.layout.select_dialog_item,s); lView.setAdapter(arr); lView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Intent i=new Intent(Intent.ACTION_DIAL); i.setData(Uri.parse("tel:"+s[position])); startActivity(i); } }); } }

Use Quizgecko on...
Browser
Browser