0% found this document useful (0 votes)
43 views

Practical No 8

The document describes an Android activity layout with an AutoCompleteTextView widget. The MainActivity class finds the AutoCompleteTextView, sets an ArrayAdapter on it with sample string values, and associates the AutoCompleteTextView to display suggestions from the adapter. This allows a user to select from predefined options as they type into the text field for autocompletion functionality.

Uploaded by

atharvabutte03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Practical No 8

The document describes an Android activity layout with an AutoCompleteTextView widget. The MainActivity class finds the AutoCompleteTextView, sets an ArrayAdapter on it with sample string values, and associates the AutoCompleteTextView to display suggestions from the adapter. This allows a user to select from predefined options as they type into the text field for autocompletion functionality.

Uploaded by

atharvabutte03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No 08

Q1.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:isScrollContainer="false"
android:keepScreenOn="false"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="306dp"
android:layout_height="429dp"
android:layout_marginTop="50dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/google" />

<AutoCompleteTextView
android:id="@+id/atc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:paddingStart="10dp" />
</LinearLayout>

<EditText
android:layout_width="162dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:singleLine="false"
android:text="Atharva Butte"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.practical8;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] searchs = new String[]{"Dog", "Donkey", "Cat"};
AutoCompleteTextView atc = findViewById(R.id.atc);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, searchs);
atc.setAdapter(adapter);
}
}

Q2.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:isScrollContainer="false"
android:keepScreenOn="false"
tools:context=".MainActivity">

<AutoCompleteTextView
android:id="@+id/atc"
android:layout_width="265dp"
android:layout_height="47dp"
android:completionThreshold="1"
android:hint="Enter Subject"
android:paddingStart="10dp"
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.482" />

<EditText
android:layout_width="162dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:singleLine="false"
android:text="Atharva Butte"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.practical8;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String [] subjects = new String[]{"PROGRAMMING WITH PYTHON","MOBILE APPLICATION
DEVELOPMENT","EMERGING TRENDS IN COMPUTER" +
" AND INFORMATION TECHNOLGY","MANAGEMENT","WEB BASED APPLICATION
DEVELOPMENT USING PHP","ENTREPRENEURSHIP DEVELOPMENT"};
AutoCompleteTextView atc = findViewById(R.id.atc);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,subjects);
atc.setAdapter(adapter);
}
}

You might also like