Practical 8 A
Practical 8 A
Exercise :-
1). Write a program to create a first display sreen of any search engine using Auto
Complete
Text View.
Code :-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search..."
android:imeOptions="actionSearch"
android:inputType="text"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
<Button
android:id="@+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_below="@id/autoCompleteTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"/>
</RelativeLayout>
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity
public class MainActivity extends AppCompatActivity
private AutoCompleteTextView autoCompleteTextView;
private Button searchButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
searchButton = findViewById(R.id.searchButton);
String[] suggestions = {"Android", "Java", "Programming", "Development", "OpenAI", "Machine Learning"}
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_dropdown_item_1line, suggestions);
autoCompleteTextView.setAdapter(adapter);
searchButton.setOnClickListener(v -> {
String query = autoCompleteTextView.getText().toString();
Toast.makeText(MainActivity.this, "Searching for: " + query, Toast.LENGTH_SHORT).show()
}};
}
}
Output :-
Subject :- Mobile Application Developmen Subject Code :- 22617
Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24
Exercise :-
1). Write a program to place Name, Age and Mobile Number linearly (vertical) on
display
screen using Linear layout.
Code :-
Output :-
Subject :- Mobile Application Developmen Subject Code :- 22617
Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24
Exercise :-
2). Write a program to place Name, Age and Mobile Number centrally on the display
screen using Absolute layout.
Code :-
Output :-