Android Lab File by Rajat
Android Lab File by Rajat
Android Lab File by Rajat
of
ANDROID APPLICATION DEVELOPMENT LAB
CSE523
SUBMITTED TO:
MR. MANISH GUPTA
Assistant Professor
CSE, AUMP
SUBMITTED BY:
Rajat Gupta
5th Semester
CSE, AUMP
A60205220005
1. Android
2. Flutter
MainActivity.java
package com.example.myapplicationseventh;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText= findViewById(R.id.edit);
textView= findViewById(R.id.textView2);
button= findViewById(R.id.button);
button2= findViewById(R.id.button2);
button3= findViewById(R.id.button3);
button4= findViewById(R.id.button4);
button5= findViewById(R.id.button5);
button6= findViewById(R.id.button6);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
double d = Double.parseDouble(s);
double pound = d * 2.205;
textView.setText("Pounds=" + pound);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
double d = Double.parseDouble(s);
double cm = d * 100;
textView.setText("Cm=" + cm);
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
double d = Double.parseDouble(s);
double $ = d * 0.013;
textView.setText("Usd=" + $);
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
double d = Double.parseDouble(s);
double f =d * 9/5 + 32;
textView.setText("°F=" + f);
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
double d = Double.parseDouble(s);
double r = d * 0.017;
textView.setText("Radian=" + r);
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String s = editText.getText().toString();
double d = Double.parseDouble(s);
double sq = d * 10000;
textView.setText("Cm²=" + sq);
}
});
}
}
Activity_main.xml
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="kg to pound"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.09"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.531" />
<TextView
android:id="@+id/textView2"
android:layout_width="255dp"
android:layout_height="25dp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.41" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="m to cm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.531" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Rupees to USD "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.93"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.531" />
<Button
android:id="@+id/button4"
android:layout_width="110dp"
android:layout_height="47dp"
android:text="°C to °F"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.094"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.653" />
<TextView
android:id="@+id/textView"
android:layout_width="200dp"
android:layout_height="73dp"
android:gravity="center"
android:text="CONVERTER APP"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.071" />
<ImageView
android:id="@+id/imageView"
android:layout_width="304dp"
android:layout_height="162dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.94"
app:srcCompat="@drawable/convert" />
<Button
android:id="@+id/button5"
android:layout_width="103dp"
android:layout_height="54dp"
android:text="Degree to Rad"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.653" />
<Button
android:id="@+id/button6"
android:layout_width="106dp"
android:layout_height="47dp"
android:text="m² to Cm²"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.901"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.646" />
</android.support.constraint.ConstraintLayout>
Output
2.LOGIN- PAGE
MainActivity.java
package com.example.login28;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit1=findViewById(R.id.h1);
edit2=findViewById(R.id.h2);
button=findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(edit1.getText().toString().equals("Gaurav") &&
edit2.getText().toString().equals("9109069816")){
Toast.makeText(MainActivity.this,"Login
success",Toast.LENGTH_SHORT).show();
}else
Toast.makeText(MainActivity.this,"Failed",Toast.LENGTH_SHORT).show();
}
});
}
}
Activity_main.xml
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="237dp"
android:layout_height="89dp"
android:gravity="center"
android:text="Login"
android:textColor="@color/purple_700"
android:textSize="48dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.073" />
<EditText
android:id="@+id/h1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_baseline_person_24"
android:drawablePadding="20dp"
android:ems="10"
android:hint="Username"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.36" />
<EditText
android:id="@+id/h2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:hint="Password"
android:drawableLeft="@drawable/ic_baseline_person_24"
android:drawablePadding="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.552" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.795" />
</android.support.constraint.ConstraintLayout>
Output
3.CALCULATOR – APP
MainActivity.java
package com.example.calcu_p;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
ImageView btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9,
btn_0;
ImageView btn_dot, btn_equal, btn_ac, btn_module, btn_plus, btn_minus,
btn_multiplication;
String data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
outPuttxt = findViewById(R.id.outPuttxt);
inputTxt = findViewById(R.id.inputTxt);
btn_0 = findViewById(R.id.btn_0);
btn_1 = findViewById(R.id.btn_1);
btn_2 = findViewById(R.id.btn_2);
btn_3 = findViewById(R.id.btn_3);
btn_4 = findViewById(R.id.btn_4);
btn_5 = findViewById(R.id.btn_5);
btn_6 = findViewById(R.id.btn_6);
btn_7 = findViewById(R.id.btn_7);
btn_8 = findViewById(R.id.btn_8);
btn_9 = findViewById(R.id.btn_9);
btn_dot = findViewById(R.id.btn_dot);
btn_equal = findViewById(R.id.btn_equal);
btn_ac = findViewById(R.id.btn_ac);
btn_module = findViewById(R.id.btn_module);
btn_plus = findViewById(R.id.btn_plus);
btn_minus = findViewById(R.id.btn_minus);
btn_multiplication = findViewById(R.id.btn_multiplication);
btn_0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "0");
}
});
btn_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "1");
}
});
btn_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "2");
}
});
btn_3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "3");
}
});
btn_4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "4");
}
});
btn_5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "5");
}
});
btn_6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "6");
}
});
btn_7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "7");
}
});
btn_8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "8");
}
});
btn_9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "9");
}
});
btn_ac.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
inputTxt.setText("");
outPuttxt.setText("");
}
});
btn_dot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + ".");
}
});
btn_plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "+");
}
});
btn_minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "-");
}
});
btn_module.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "%");
}
});
btn_multiplication.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
inputTxt.setText(data + "×");
}
});
btn_equal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
data = inputTxt.getText().toString();
outPuttxt.setText(finalResult);
});
}
}
Activity_main.xml
<TextView
android:id="@+id/inputTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/outPuttxt"
android:gravity="right"
android:paddingRight="20dp"
android:textColor="#535353"
android:textSize="40dp" />
<TextView
android:id="@+id/outPuttxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/buttons"
android:gravity="right"
android:paddingRight="20dp"
android:textColor="@color/white"
android:textSize="90dp" />
<LinearLayout
android:id="@+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_1"
android:visibility="invisible" />
<ImageView
android:id="@+id/btn_ac"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_ac" />
<ImageView
android:id="@+id/btn_module"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_module" />
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_extra" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:id="@+id/btn_7"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_7" />
<ImageView
android:id="@+id/btn_8"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_8" />
<ImageView
android:id="@+id/btn_9"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_9" />
<ImageView
android:id="@+id/btn_multiplication"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_multiplication" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:id="@+id/btn_4"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_4" />
<ImageView
android:id="@+id/btn_5"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_5" />
<ImageView
android:id="@+id/btn_6"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_6" />
<ImageView
android:id="@+id/btn_plus"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_plus"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:id="@+id/btn_1"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_1" />
<ImageView
android:id="@+id/btn_2"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_2" />
<ImageView
android:id="@+id/btn_3"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_3" />
<ImageView
android:id="@+id/btn_minus"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_minus" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingBottom="5dp">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="25dp"
android:layout_marginLeft="25dp"
android:layout_marginEnd="25dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_1"
android:visibility="invisible" />
<ImageView
android:id="@+id/btn_0"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_0" />
<ImageView
android:id="@+id/btn_dot"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/btn_dot" />
<ImageView
android:id="@+id/btn_equal"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="25dp"
android:background="@drawable/equal" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Output
4.Check-Box
Mainactivity.xml
package com.example.checkbox;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit=findViewById(R.id.e1);
button=findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(edit.getText().toString().equals("Hello")){
});
}
}
activitymain.xml
<TextView
android:id="@+id/textView"
android:layout_width="97dp"
android:layout_height="44dp"
android:gravity="center"
android:text="ITEMS"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.116" />
<EditText
android:id="@+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter the field"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.411" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.695" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output :-
5.Student Placement App
Mainactivity.xml
package com.mywbut.studentapp;
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;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
EditText cgpa,iq,profile_score;
Button predict;
TextView result;
String url = "https://campusx-student-app.herokuapp.com/predict";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cgpa = findViewById(R.id.cgpa);
iq = findViewById(R.id.iq);
profile_score = findViewById(R.id.profile_score);
predict = findViewById(R.id.predict);
result = findViewById(R.id.result);
predict.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// hit the API -> Volley
StringRequest stringRequest = new
StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String data = jsonObject.getString("placement");
if(data.equals("1")){
result.setText("Placement Hoga");
}else{
result.setText("Placement Nahi Hoga");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.getMessage(),
Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String,String>();
params.put("cgpa",cgpa.getText().toString());
params.put("iq",iq.getText().toString());
params.put("profile_score",profile_score.getText().toString());
return params;
}
};
RequestQueue queue = Volley.newRequestQueue(MainActivity.this);
queue.add(stringRequest);
}
});
}
}
activity_main.xml
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Student Placement Predictor"
android:textSize="30dp"
android:textAlignment="center"
android:layout_marginTop="30dp"></TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="CGPA"
android:id="@+id/cgpa"
android:layout_marginTop="20dp"
></EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="IQ"
android:id="@+id/iq"
android:layout_marginTop="20dp"
></EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="profile_score"
android:id="@+id/profile_score"
android:layout_marginTop="20dp"
></EditText>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Predict"
android:layout_marginTop="30dp"
android:id="@+id/predict"></Button>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="50dp"
android:textAlignment="center"
android:layout_marginTop="80dp"
android:id="@+id/result"></TextView>
</LinearLayout>
Output
6.LOGIN PAGE – FLUTTER
Main.dart
import 'package:flutter/material.dart';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatefulWidget(),
),
);
}
}
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(10),
child: const Text(
'SIGN IN PAGE',
style: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.w500,
fontSize: 30),
)),
Container(
padding: const EdgeInsets.all(10),
child: TextField(
controller: nameController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'User Name',
),
),
),
Container(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: TextField(
obscureText: true,
controller: passwordController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
),
),
TextButton(
onPressed: () {
//forgot password screen
},
child: const Text('Forgot Password',),
),
Container(
height: 50,
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: ElevatedButton(
child: const Text('Login'),
onPressed: () {
print(nameController.text);
print(passwordController.text);
},
)
),
Row(
children: <Widget>[
const Text('Does not have account?'),
TextButton(
child: const Text(
'Sign in',
style: TextStyle(fontSize: 20),
),
onPressed: () {
//signup screen
},
)
],
mainAxisAlignment: MainAxisAlignment.center,
),
],
));
}
}
Output
7.VALIDATION-FORM
Main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: FormValidationExample(),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Form validation example'),
),
body:
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child:Form(
key: formGlobalKey,
child: Column(
children: [
const SizedBox(height: 50),
TextFormField(
decoration: InputDecoration(
labelText: "Email"
),
validator: (email) {
if (isEmailValid(email!)) return null;
else
return 'Enter a valid email address';
},
),
const SizedBox(height: 24),
TextFormField(
decoration: InputDecoration(
labelText: "Password",
),
maxLength: 6,
obscureText: true,
validator: (password) {
if (isPasswordValid(password!)) return null;
else
return 'Enter a valid password';
},
),
const SizedBox(height: 50),
ElevatedButton(
onPressed: () {
if (formGlobalKey.currentState!.validate()) {
formGlobalKey.currentState!.save();
// use the email provided here
}
},
child: Text("Submit"))
],
),
),
));
}
}
mixin InputValidationMixin {
bool isPasswordValid(String password) => password.length == 6;
Main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Forms(),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('VALIDATION FORM'),
),
body:
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child:Form(
key: formGlobalKey,
child: Column(
children: [
),
validator: (name) {
if (isNameValid(name!)) return null;
else
return 'Enter a name';
},
),
screen({
this.name,this.email,this.phone,this.course
});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("Name: " + name.toString(),style: TextStyle(fontSize: 20),),
Text("E-mail: " + email.toString(),style: TextStyle(fontSize: 20)),
Text("Phone no.: " + phone.toString(),style: TextStyle(fontSize: 20)),
Text("Course: " + course.toString(),style: TextStyle(fontSize: 20)),
],
),
),
),
);
}
}
Output:-
9.LIST-VIEW
Main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Forms(),
));
}
class Forms extends StatelessWidget {
TextEditingController name = new TextEditingController();
TextEditingController phone = new TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('LISTVIEW FORM'),
centerTitle: true,
),
body:
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child:Form(
child: Column(
children: [
const SizedBox(height: 50),
TextFormField(
controller: name,
decoration: InputDecoration(
labelText: "Name",
hintText: "Enter name",
border: OutlineInputBorder(),
),
),
const SizedBox(height: 50),
TextFormField(
controller: phone,
decoration: InputDecoration(
labelText: "Phone no.",
hintText: "Enter phone no.",
border: OutlineInputBorder(),
),
),
const SizedBox(height: 50),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder:
(context)=>screen(name: name.text, phone: phone.text)));
},
child: Text("Submit"))
],
),
),
));
}
}
class screen extends StatelessWidget {
String? name,phone;
screen({
this.name,this.phone
});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: ListView(
children: [
Text("Name: " + name.toString(),style: TextStyle(fontSize: 20),),
Text("Phone no.: " + phone.toString(),style: TextStyle(fontSize: 20)),
],
),
),
),
);
}
}
Output
10.REGISTRATION FORM WITH (VALIDATION LOGIC)
Main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Forms(),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('VALIDATION FORM'),
),
body:
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child:Form(
key: formGlobalKey,
child: Column(
children: [
),
validator: (name) {
if (isNameValid(name!)) return null;
else
return 'Enter a name';
},
),
screen({
this.name,this.email,this.phone,this.course
});
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("Name: " + name.toString(),style: TextStyle(fontSize: 20),),
Text("E-mail: " + email.toString(),style: TextStyle(fontSize: 20)),
Text("Phone no.: " + phone.toString(),style: TextStyle(fontSize: 20)),
Text("Course: " + course.toString(),style: TextStyle(fontSize: 20)),
],
),
),
),
);
}
}
Output
11.QUIZ – APP
Main.dart
import 'package:flutter/material.dart';
import 'package:flutter_mentor_quiz_app_tut/home.dart';
void main() {
runApp(MyApp());
}
home.dart
import 'package:flutter/material.dart';
import 'package:flutter_mentor_quiz_app_tut/answer.dart';
void _nextQuestion() {
setState(() {
_questionIndex++;
answerWasSelected = false;
correctAnswerSelected = false;
});
// what happens at the end of the quiz
if (_questionIndex >= _questions.length) {
_resetQuiz();
}
}
void _resetQuiz() {
setState(() {
_questionIndex = 0;
_totalScore = 0;
_scoreTracker = [];
endOfQuiz = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Flutter Quiz App',
style: TextStyle(color: Colors.white),
),
centerTitle: true,
),
body: Center(
child: Column(
children: [
Row(
children: [
if (_scoreTracker.length == 0)
SizedBox(
height: 25.0,
),
if (_scoreTracker.length > 0) ..._scoreTracker
],
),
Container(
width: double.infinity,
height: 130.0,
margin: EdgeInsets.only(bottom: 10.0, left: 30.0, right: 30.0),
padding: EdgeInsets.symmetric(horizontal: 50.0, vertical: 20.0),
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.circular(10.0),
),
child: Center(
child: Text(
_questions[_questionIndex]['question'],
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
...(_questions[_questionIndex]['answers']
as List<Map<String, Object>>)
.map(
(answer) => Answer(
answerText: answer['answerText'],
answerColor: answerWasSelected
? answer['score']
? Colors.green
: Colors.red
: null,
answerTap: () {
// if answer was already selected then nothing happens onTap
if (answerWasSelected) {
return;
}
//answer is being selected
_questionAnswered(answer['score']);
},
),
),
SizedBox(height: 20.0),
ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: Size(double.infinity, 40.0),
),
onPressed: () {
if (!answerWasSelected) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Please select an answer before going to the next question'),
));
return;
}
_nextQuestion();
},
child: Text(endOfQuiz ? 'Restart Quiz' : 'Next Question'),
),
Container(
padding: EdgeInsets.all(20.0),
child: Text(
'${_totalScore.toString()}/${_questions.length}',
style: TextStyle(fontSize: 40.0, fontWeight: FontWeight.bold),
),
),
if (answerWasSelected && !endOfQuiz)
Container(
height: 100,
width: double.infinity,
color: correctAnswerSelected ? Colors.green : Colors.red,
child: Center(
child: Text(
correctAnswerSelected
? 'Well done, you got it right!'
: 'Wrong :/',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
if (endOfQuiz)
Container(
height: 100,
width: double.infinity,
color: Colors.black,
child: Center(
child: Text(
_totalScore > 4
? 'Congratulations! Your final score is: $_totalScore'
: 'Your final score is: $_totalScore. Better luck next time!',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: _totalScore > 4 ? Colors.green : Colors.red,
),
),
),
),
],
),
),
);
}
}
{
'question': 'OHA Full form ?',
'answers': [
{'answerText': 'Ov Handset Alliance', 'score': false},
{'answerText': 'Open Handset Alliance', 'score': true},
{'answerText': 'Open Hand Alliance', 'score': false},
],
},
];
answer.dart
import 'package:flutter/material.dart';
@override
Widget build(BuildContext context) {
return InkWell(
onTap: answerTap,
child: Container(
padding: EdgeInsets.all(15.0),
margin: EdgeInsets.symmetric(vertical: 5.0, horizontal: 30.0),
width: double.infinity,
decoration: BoxDecoration(
color: answerColor,
border: Border.all(color: Colors.blue),
borderRadius: BorderRadius.circular(20.0),
),
child: Text(
answerText,
style: TextStyle(
fontSize: 15.0,
),
),
),
);
}
}
Output:-