أخر الاخبار

examples in android studio

 


EX/ program celsius to fahrenheit and  fahrenheit to celsius ?

sol//





XML 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layoutDirection="ltr"
android:textDirection="ltr"
tools:context=".degress">

<EditText
android:id="@+id/edit1"
android:layout_width="150sp"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:layout_marginLeft="120sp"
android:hint="enter"/>
<Button
android:id="@+id/fToc"
android:layout_below="@id/edit1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120sp"
android:layout_marginTop="20sp"
android:text="ftoc"/>
<Button
android:id="@+id/cTof"
android:layout_below="@id/fToc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120sp"
android:layout_marginTop="20sp"
android:text="ctof"/>

<TextView
android:id="@+id/result"
android:layout_below="@id/cTof"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20sp"
android:layout_marginLeft="120sp"
android:text="0 Degress"/>

</RelativeLayout>

JAVA

package com.project.test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class degress extends AppCompatActivity {
private Button cTof,fToc;
private TextView res;
private EditText enter;
double res0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_degress);

cTof=findViewById(R.id.cTof);
fToc=findViewById(R.id.fToc);
res=findViewById(R.id.result);
enter=findViewById(R.id.edit1);

cTof.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double temp=Double.parseDouble(enter.getText().toString());
res0=(temp *1.8) + 32;
res.setText(String.valueOf(res0));
}
});

fToc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double temp=Double.parseDouble(enter.getText().toString());
res0=(temp -32) / 1.8;
res.setText(String.valueOf(res0));
}
});
}
}



EX/ Q1) Contract application mobile using eclipse android (using XML and Java languages) is calculated
100*500=50000 and reset it and emulated this application. The application has Blue
background, the button is Yellow color.

sol/

XML

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000FF"
android:orientation="vertical" >

<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="20sp"
android:textStyle="bold" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:textColor="#FFFFFF"
android:background="#FFFF00" />

</LinearLayout>


JAVA

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

private TextView result;
private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

result = (TextView) findViewById(R.id.result);
button = (Button) findViewById(R.id.button);

// perform the calculation on app launch
int calculation = 100*500;
result.setText(String.valueOf(calculation));

// set on click listener for the button
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
result.setText("0");
}
});
}
}


ex/Write the code with example the array in listview in java eclipse?

sol//

XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000FF"
android:orientation="vertical" >





<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>


</LinearLayout>


JAVA
package com.project.test;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

private ListView listView;
private String[] items = {"Item 1", "Item 2", "Item 3", "Item 4"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView);

ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, items);
listView.setAdapter(adapter);


}
}






تعليقات



حجم الخط
+
16
-
تباعد السطور
+
2
-