• RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
Posted by Jack - - 4 comments

Android – Simple AutoCompleteTextView Example

Source main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<AutoCompleteTextView
android:id="@+id/autocompletetextview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" >
</AutoCompleteTextView>

</LinearLayout>


Source AutoCompleteTextViewExampleActivity.java

package com.actvex;

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

public class AutoCompleteTextViewExampleActivity extends Activity {

    AutoCompleteTextView autocompletetextview;

    String[] array = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
            "Eight", "Nine", "Ten" };


    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        autocompletetextview = (AutoCompleteTextView)     findViewById(R.id.autocompletetextview);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.select_dialog_item,
array);

        autocompletetextview.setThreshold(1);

        autocompletetextview.setAdapter(adapter);


    }
}


The Output will be







Posted by Jack - - 3 comments


Android – Selector on Button Example

Source button.xml

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />

<item android:drawable="@drawable/button_normal"
android:state_focused="true" />

<item android:drawable="@drawable/button_normal" />

</selector>


Source main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<Button
android:id="@+id/button1"
android:layout_width="80dp"
android:layout_height="40dp"
android:background="@drawable/button"
android:textColor="#ffffff"
android:text="Button" />

</LinearLayout>

The output will be