Sunday, September 15, 2013

Simple AutoCompleteTextView Example

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 28- APR- 2011 11 COMMENTS

SIMPLE EDITTEXT

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

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

<EditText android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

    <Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show the Text" />

</LinearLayout>

SOURCE CODE [EditTextExample.java] is

package com.EditTextExample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class EditTextExample extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
                                
final EditText et;
final Button b;
        
et = (EditText) findViewById(R.id.edittext);
b = (Button) findViewById(R.id.button);
        
                                b.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
                                                                String text=et.getText().toString();
                                                                
                                                Toast msg = Toast.makeText(getBaseContext(),
                                                                                text, Toast.LENGTH_LONG);
msg.show();
                                                }
                                });
}
}

The OUTPUT will be


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJMcNhUc1yGsWc2lzNa4XDUM_aLyfP1Zcqm5BaRkQn_slHAPrmomTcVvbGdTFdUChxaGgO6UEb2ZizGZoDq74WbVqE_HUKTL051aQq-WxYH8BBBBFt9ON6aaAdFOYLXU91bwl3D_Gaj6g/


https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJR-70eeELlnzrVR1Uw4JIAg-OP_GqRXjXFOc_5GfsrEMfoTFzzPsEWyGGVRATs20VW3zV-18LAGjpl26wix04fneBWHfPUb8ugo1AIeTF1emp1x8absuIpilOjvG9lxeXJJDPXgAx1yQ/

No comments:

Post a Comment