Mobile Application and Development-Lec8
Mobile Application and Development-Lec8
</RelativeLayout>
Scenario 1
Scenario 2
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.geeksforgeeks.Spinner.MainActivity">
<Spinner
android:id="@+id/coursesspinner"
android:layout_height="50dp"
android:layout_width="160dp"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"/>
</LinearLayout>
Scenario 2
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spino = findViewById(R.id.coursesspinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter ad
= new ArrayAdapter(this,
android.R.layout.simple_spinner_item,
courses);
@Override
public class MainActivity extends AppCompatActivity { public void onClick(View view) {
CheckBox pizza,coffe,burger; int totalamount=0;
Button buttonOrder; StringBuilder result=new StringBuilder();
@Override result.append("Selected Items:");
protected void onCreate(Bundle savedInstanceState) { if(pizza.isChecked()){
super.onCreate(savedInstanceState); result.append("\nPizza 100Rs");
setContentView(R.layout.activity_main); totalamount+=100;
addListenerOnButtonClick(); }
} if(coffe.isChecked()){
public void addListenerOnButtonClick(){ result.append("\nCoffe 50Rs");
//Getting instance of CheckBoxes and Button from the totalamount+=50;
activty_main.xml file }
pizza=(CheckBox)findViewById(R.id.checkBox); if(burger.isChecked()){
coffe=(CheckBox)findViewById(R.id.checkBox2); result.append("\nBurger 120Rs");
burger=(CheckBox)findViewById(R.id.checkBox3); totalamount+=120;
buttonOrder=(Button)findViewById(R.id.button); }
result.append("\nTotal: "+totalamount+"Rs");
//Applying the Listener on the Button click //Displaying the message on the toast
buttonOrder.setOnClickListener(new View.OnClickListener(){ Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}
Scenario 3
Scenario 4
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
Scenario 4
<resources>
<string name="app_name">ListView</string>
<string-array name="array_technology">
<item>Android</item>
<item>Java</item>
<item>Php</item>
<item>Hadoop</item>
<item>Sap</item>
<item>Python</item>
<item>Ajax</item>
<item>C++</item>
<item>Ruby</item>
<item>Rails</item>
<item>.Net</item>
<item>Perl</item>
</string-array>
</resources>
Scenario 5
}
});
}
}
Scenario 5
Scenario 6:
Write xml code of screen which takes two number as input and provide buttons for add, subtract,
multiply and divide buttons. Result to be displayed at the end.
Scenario 6: Linear Layout
<LinearLayout <Button
android:layout_width="match_parent" android:id="@+id/btnSubtract"
android:layout_height=" wrap_content" android:layout_width=“match_parent"
android:orientation="vertical" android:layout_height="wrap_content"
android:text="Subtract"/>
<EditText
android:id="@+id/num1" <Button
android:layout_width="match_parent" android:id="@+id/btnMultiply"
android:layout_height="wrap_content" android:layout_width=" match_parent "
android:hint="Enter first number" android:layout_height="wrap_content"
android:inputType="number"/> android:text="Multiply"/>
<EditText <Button
android:id="@+id/num2" android:id="@+id/btnDivide"
android:layout_width="match_parent" android:layout_width=" match_parent "
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Enter second number" android:text="Divide"/>
android:inputType="number" />
<TextView
<Button android:id="@+id/resultText"
android:id="@+id/btnAdd" android:layout_width=" match_parent "
android:layout_width=“match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Result: "
android:text="Add"/> android:textSize="18sp"/>
</LinearLayout>
Scenario 6: Relative Layout
<RelativeLayout <Button
android:layout_width="match_parent" android:id="@+id/btnSubtract"
android:layout_height="match_parent" android:layout_width="match_parent"
<EditText android:layout_height="wrap_content"
android:id="@+id/num1" android:text="Subtract"
android:layout_width="match_parent" android:layout_below="@id/btnAdd"/>
android:layout_height="wrap_content" <Button
android:hint="Enter first number" android:id="@+id/btnMultiply"
android:inputType="number" /> android:layout_width="match_parent"
<EditText android:layout_height="wrap_content"
android:id="@+id/num2" android:text="Multiply"
android:layout_width="match_parent" android:layout_below="@id/btnSubtract"/>
android:layout_height="wrap_content" <Button
android:hint="Enter second number" android:id="@+id/btnDivide"
android:inputType="number" android:layout_width="match_parent"
android:layout_below="@id/num1"/> android:layout_height="wrap_content"
<Button android:text="Divide"
android:id="@+id/btnAdd" android:layout_below="@id/btnMultiply"/>
android:layout_width="match_parent" <TextView
android:layout_height="wrap_content" android:id="@+id/tvResult"
android:text="Add" android:layout_width="match_parent"
android:layout_below="@id/num2"/> android:layout_height="wrap_content"
android:text="Result:"
android:layout_below="@id/btnDivide"/>
</RelativeLayout>
Scenario 6: Tabular Layout
<TableLayout <TableRow>
android:layout_width="match_parent" <Button
android:layout_height="match_parent" android:id="@+id/btnAdd"
android:layout_width="match_parent"
<TableRow> android:layout_height="wrap_content"
<EditText android:text="Add"/>
android:id="@+id/num1" </TableRow>
android:layout_width="match_parent"
android:layout_height="wrap_content" <TableRow>
android:hint="Enter first number" <Button
android:inputType="number"/> android:id="@+id/btnSubtract"
</TableRow> android:layout_width="match_parent"
android:layout_height="wrap_content"
<TableRow> android:text="Subtract"/>
<EditText </TableRow>
android:id="@+id/num2"
android:layout_width="match_parent" <TableRow>
android:layout_height="wrap_content" <Button
android:hint="Enter second number" android:id="@+id/btnMultiply"
android:inputType="number"/> android:layout_width="match_parent"
</TableRow> android:layout_height="wrap_content"
android:text="Multiply"/>
</TableRow>
Scenario 6: Tabular Layout
<TableRow>
<Button
android:id="@+id/btnDivide"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Divide"/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Result:"/>
</TableRow>
</TableLayout>