res\layout\activity main xml xml version= 0" encoding="utf-8"


Download 42.39 Kb.
Sana18.06.2023
Hajmi42.39 Kb.
#1568026
Bog'liq
8. AutoCompleteTextView


*****res\layout\activity_main.xml


xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

android:id="@+id/autocomplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="City"
android:completionThreshold="1"
/>


*****MainActivity.java


package com.example.test_6;

import androidx.appcompat.app.AppCompatActivity;


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

public class MainActivity extends AppCompatActivity {


String[] cities={"India","Australia","West indies","indonesia","Indiana", "South Africa","England","Bangladesh","Srilanka","singapore"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autocomplete);


ArrayAdapter adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, cities);
autoCompleteTextView.setAdapter(adapter);
}
}

Download 42.39 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling