Department of Computer Science
Android Programming
Final Term (Fall 2022)
BSCS 7th Semester (Evening)
a) Unit Converter:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private Button button;
private TextView textView;
private EditText editText;
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
button = findViewById([Link]);
textView = findViewById([Link]);
editText = findViewById([Link]);
public void onClick(View v){
String s = [Link]().toString();
int kg = [Link](s);
double pound = 2.205 * kg;
[Link]("The corresponding value in Pounds is " + pound);
[Link](this, "Thanks for using this app",
Toast.LENGTH_SHORT).show();
}}
b) Sticky Notes App
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Department of Computer Science
Android Programming
Final Term (Fall 2022)
BSCS 7th Semester (Evening)
import [Link];
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
MaterialButton addNoteBtn = findViewById([Link]);
TextView noNotes = findViewById([Link]);
[Link](v -> {
startActivity(new Intent([Link], [Link]));
});
[Link](getApplicationContext());
Realm realm = [Link]();
RealmResults<Note> notesList = [Link]([Link])
.findAllSorted("createdTime", [Link]);
if ([Link]()) {
[Link]([Link]);
} else {
[Link]([Link]);
}
RecyclerView recyclerView = findViewById([Link]);
[Link](new LinearLayoutManager(this));
MyAdapter myAdapter = new MyAdapter(getApplicationContext(),
notesList);
[Link](myAdapter);
[Link](new
RealmChangeListener<RealmResults<Note>>() {
public void onChange(RealmResults<Note> notes) {
if ([Link]()) {
[Link]([Link]);
} else {
[Link]([Link]);
}
[Link]();
}});}}
c) Food App Login Page
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class login extends AppCompatActivity {
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) {
[Link](savedInstanceState);
setContentView([Link].activity_login);
user=findViewById([Link]);
pass=findViewById([Link]);
login=findViewById([Link]);
[Link](new [Link]() {
public void onClick(View view) {
if ([Link]().toString().equals("admin") &&
[Link]().toString().equals("admin"))
{
Intent intent=new Intent([Link],[Link]);
startActivity(intent);
}
else {
[Link]([Link],"Username or Password
Incorrect",Toast.LENGTH_SHORT).show();
}
if ([Link]([Link]().toString())){
[Link]("Please Enter User Name");
return;
}
else if ([Link]([Link]().toString())){
[Link]("Please Enter Password");
return;}}});}}
2) Define the following built-in functions:
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.