Final Term Paper Android Programming Solution
Final Term Paper Android Programming Solution
Android Programming
Final Term (Fall 2022)
BSCS 7th Semester (Evening)
a) Unit Converter:
package com.example.unconvert;
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 androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import io.realm.Realm;
import io.realm.RealmChangeListener;
import io.realm.RealmResults;
import io.realm.Sort;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
Department of Computer Science
Android Programming
Final Term (Fall 2022)
BSCS 7th Semester (Evening)
import com.google.android.material.button.MaterialButton;
if (notesList.isEmpty()) {
noNotes.setVisibility(View.VISIBLE);
} else {
noNotes.setVisibility(View.GONE);
}
myAdapter.notifyDataSetChanged();
}});}}
c) Food App Login Page
package com.example.foodgram;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText user;
EditText pass;
Button login;
Department of Computer Science
Android Programming
Final Term (Fall 2022)
BSCS 7th Semester (Evening)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
user=findViewById(R.id.user);
pass=findViewById(R.id.pass);
login=findViewById(R.id.button);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (user.getText().toString().equals("admin") &&
pass.getText().toString().equals("admin"))
{
Intent intent=new Intent(login.this,MainActivity.class);
startActivity(intent);
}
else {
Toast.makeText(login.this,"Username or Password
Incorrect",Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(user.getText().toString())){
user.setError("Please Enter User Name");
return;
}
else if (TextUtils.isEmpty(pass.getText().toString())){
pass.setError("Please Enter Password");
return;}}});}}
toString():
A toString() is an in-built method in Java that returns the value given to it in string format.
getApplicationContext ():
It is used to return the Context which is linked to the Application which holds all activities running inside it. When
we call a method or a constructor, we often have to pass a Context and often we use “this” to pass the activity
Context or “getApplicationContext” to pass the application Context.
putExtra():
the putExtra() method is used to send data between Android activities.
trim():
The trim() method removes whitespace from both sides of a string. The trim() method does not change the original
string.
equals(): The equals() method compares two strings, and returns true if the strings are equal, and false if not.