Sunday 21 May 2017

AutocompletetextView

1) activity_main.xml
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_below="@+id/button"
        android:orientation="vertical" >

        <AutoCompleteTextView
            android:id="@+id/autotxtCategory"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/wildlife"
            android:drawableRight="@drawable/downarro"
            android:ems="10"
            android:hint="@string/category"
            android:imeOptions="actionNext"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textSize="@dimen/edt_text_size" />
    </LinearLayout>

2)auto_list_item
===========
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/val_10"
    android:textSize="@dimen/txt_medium_size"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textColor="@color/Black"
    android:text="elk"/>
3)AutoCompleteTextView
===================
package com.example.facebooksharingdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class Autocompletext extends Activity{
private AutoCompleteTextView autoCategory;
private ArrayAdapter<String> aadpCategory;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCategory = (AutoCompleteTextView) findViewById(R.id.autotxtCategory);
aadpCategory = new ArrayAdapter<String>(this, R.layout.auto_list_item, alstCatName);
autoCategory.setAdapter(aadpCategory);

autoCategory.setThreshold(1);

autoCategory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
autoCategory.showDropDown();
}
});

autoCategory.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
intCatId = alstCatId.get(position);
System.out.println("intCatId:::Selected::::****==" + intCatId);
GetSubCategoryData(intCatId);
}
});
}

}

No comments:

Post a Comment