0% found this document useful (0 votes)
14 views4 pages

LAB 9 Array Adapter

Uploaded by

mca231419ics
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)
14 views4 pages

LAB 9 Array Adapter

Uploaded by

mca231419ics
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/ 4

Name:-Aman Verma MET – Institute of Computer Science

Roll No:1266

Experiment:-9
Array Adapter

Q) Write a program to implement array adapter in Android Studio


Code:-
activityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">

<TextView
android:id="@+id/head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Typing to Get Suggestion"
android:layout_gravity="center"
android:layout_marginTop="45dp"
android:textSize="25dp"
android:layout_centerHorizontal="true"
android:textColor="#F44336"
android:textStyle="bold"
></TextView>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_below="@id/head"
android:id="@+id/Autotxt1"/>

</RelativeLayout>

MainActivity.java
Name:-Aman Verma MET – Institute of Computer Science
Roll No:1266

package com.example.arrayadapter;

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {


AutoCompleteTextView at;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] lang={"C","C++","C#","PHP","Python","Java","JavaScript","Android"};
at=findViewById(R.id.Autotxt1);
ArrayAdapter<String> adapter=new
ArrayAdapter<String>(this,android.R.layout.select_dialog_item,lang);
at.setThreshold(1);
at.setAdapter(adapter);
at.setTextColor(Color.BLUE);
}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Name:-Aman Verma MET – Institute of Computer Science
Roll No:1266

android:supportsRtl="true"
android:theme="@style/Theme.ArrayAdapter"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>

</manifest>

Output:-
Name:-Aman Verma MET – Institute of Computer Science
Roll No:1266

You might also like