CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren 2018-2019 SPRING Computer Engineering Department CMPE419 AU
Example:(Table Layout)
<TableLayout xmlns:android="http://schemas. android xmlns:tools="http://schemas.android.com/tools" android:id="@+id/TableLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.CMPE419.gpa.MainActivity" > <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Name " /> <EditText android:id="@+id/editText1" android:layout_width="131dp" android:ems="10" /> </TableRow> android:id="@+id/tableRow2" android:id="@+id/textView2" android:text="Surname " /> android:id="@+id/editText2" android:layout_width="163dp" android:ems="10" > <requestFocus /> </EditText> ... </TableLayout>
<TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height="wrap_content" > android:text="Column 0" /> <Button android:id="@+id/button1" android:layout_height="wrap_content" android:text="Button" /> </TableRow>
Get Values From EditText: final EditText m1=(EditText)findViewById(R.id.editText3); final EditText m2=(EditText)findViewById(R.id.editText4); final EditText fin=(EditText)findViewById(R.id.editText5); String m11=m1.getText().toString(); mt1=Double.parseDouble(m11); String m22= m2.getText().toString(); mt2=Double.parseDouble(m22); //mt2=Double.valueof(m22); String fin2=fin.getText().toString(); fina=Double.parseDouble(fin2); double tot=mt1*0.25+mt2*0.25+fina*0.5;
Button b1=(Button)findViewById(R.id.button1); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String m11=m1.getText().toString(); mt1=Double.parseDouble(m11); String m22= m2.getText().toString(); mt2=Double.parseDouble(m22); //mt2=Double.valueof(m22); String fin2=fin.getText().toString(); fina=Double.parseDouble(fin2); double tot=mt1*0.25+mt2*0.25+fina*0.5; Tv.setText(""+tot); } });
Add Picture to your Project Add a Picture: Step 1: Create a Project with main activity Step 2: Goto your Workspace directory and find your project name. Step 3: Open drawable-hdpi directory and copy your picture into this directory. Step 4: From Eclips menu select Project and than clean for recognizing picture. Step 5: Goto xml file and use properties and Background options to select your picture (Under Drawable)(If error occures restart Eclips).
Password Field:
Android radio buttons example: In Android, you can use “android.widget.RadioButton” class to render radio button, and those radio buttons are usually grouped by android.widget.RadioGroup. If RadioButtons are in group, when oneRadioButton within a group is selected, all others are automatically deselected.
Intent and Moving Data between Activities Step 1: Create MainActivity Step2: Create NewActivity Step3: Create new Intent in MainActivity Step4: Send your data from MainActivity using putExtra method Step5: Get data in NewActivity using getIntent().getExtras()
package com.example.cmpe; public class MainActivity extends Activity { EditText Et1_name; EditText Et2_surname; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Et1_name=(EditText)findViewById(R.id.editText1); Et2_surname=(EditText)findViewById(R.id.editText2); Button Bt=(Button)findViewById(R.id.button1); Bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //startActivity(new Intent("android.intent.action.MYNEW")); String name=Et1_name.getText().toString(); String surname=Et2_surname.getText().toString(); //Creating a new intent Intent intent=new Intent(MainActivity.this, MyNew.class); //Sending data to next activity using putExtra method intent.putExtra("NAME", name); intent.putExtra("SURNAME", surname); //starting new activity startActivity(intent); } }); }
package com.example.cmpe; public class MyNew extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mynew); final TextView T1=(TextView)findViewById(R.id.textView2); final TextView T2=(TextView)findViewById(R.id.textView4); Bundle bunble=getIntent().getExtras(); if(bunble!=null){ //Getting the value stored in the name "NAME" String user_name=bunble.getString("NAME"); String user_surname=bunble.getString("SURNAME"); //appending the value to the contents of textView1. T1.append(" "+user_name); T2.append(" "+user_surname); } final Button b=(Button)findViewById(R.id.button1); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub finish(); }}); }}