Wednesday, December 26, 2012

Search in Custom ListView On Button Click Example


SEARCH IN CUSTOM LISTVIEW ON BUTTON CLICK

SOURCE CODE [main.xml] is

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

                <Button android:text="Search"
android:id="@+id/Button01"
                                android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
                                android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>

                <EditText android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
android:text="" android:id="@+id/EditText01"
                                android:layout_toLeftOf="@+id/Button01">
</EditText>

                <ListView android:layout_height="wrap_content"
                                android:layout_below="@+id/EditText01"
android:layout_width="wrap_content"
                                android:id="@+id/ListView01">
</ListView>
                                
</RelativeLayout>

Android - Search in Custom ListView Example


SEARCH IN CUSTOM LISTVIEW

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">

                <EditText android:id="@+id/EditText01"
android:layout_height="wrap_content"
                                android:layout_width="fill_parent"
android:hint="Search">                               
                </EditText>

                <ListView android:id="@+id/ListView01"
android:layout_height="wrap_content"
                                android:layout_width="fill_parent">
</ListView>

</LinearLayout>

Android Emulator Keyboard Shortcuts


EMULATOR KEYBOARD SHORTCUTS

Emulator Device Key
Keyboard Key
Home
HOME
Menu (left softkey)
F2 or Page-up button
Star (right softkey)
Shift-F2 or Page Down
Back
ESC
Call/dial button
F3
Hangup/end call button
F4
Search
F5
Power button
F7
Audio volume up button
KEYPAD_PLUS, Ctrl-5
Audio volume down button
KEYPAD_MINUS, Ctrl-F6
Camera button
Ctrl-KEYPAD_5, Ctrl-F3
Switch to previous layout orientation
KEYPAD_7, Ctrl-F11
Switch to next layout orientation
KEYPAD_9, Ctrl-F12
Toggle cell networking on/off
F8
Toggle code profiling
F9 (only with -trace startup option)
Toggle fullscreen mode
Alt-Enter
Toggle trackball mode
F6
Enter trackball mode temporarily
Delete
DPad left/up/right/down
KEYPAD_4/8/6/2
DPad center click
KEYPAD_5
Onion alpha increase/decrease
KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/)

Android - Hide Title Bar & Status Bar through AndroidManifest.xml


HIDE THE TITLE BAR AND STATUS BAR (FULLSCREEN)

<activity android:name=".YourClassName"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>

Android - Function to convert ImageURL to Bitmap object

IMAGE URL TO BITMAP

Use this function “convertURLtoBitmap”

public Bitmap convertURLtoBitmap(String src) {

                try {

                                URL url = new URL(src);
                                                
                                HttpURLConnection connection = (HttpURLConnection) url
                                                .openConnection();

                                connection.setDoInput(true);
                                connection.connect();

                                InputStream input = connection.getInputStream();
                                Bitmap myBitmap = BitmapFactory.decodeStream(input);

                                return myBitmap;

                }

                catch (IOException e) {

                                e.printStackTrace();
                                return null;

                }
}

Email Validation Function


public boolean validateEmail(String email) {

Pattern pattern;
Matcher matcher;
String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
pattern = Pattern.compile(EMAIL_PATTERN);
matcher = pattern.matcher(email);
return matcher.matches();

}

Searching the elements of a String array, starts with SEARCHTEXT (String)


Searching the elements of a String array, starts with SEARCHTEXT (String)

public static ArrayList<String> searchFromStart(String[] inputArray, String searchText) {

            ArrayList<String> outputArray = new ArrayList<String>();

            for (int i = 0; i < inputArray.length; i++) {

                        if (searchText.compareToIgnoreCase(inputArray[i].substring(0,
                                                searchText.length())) == 0) {

                                    outputArray.add(inputArray[i]);

                        }

            }

            return outputArray;
}

Android Simple GridView Example


SIMPLE GRIDVIEW

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" />

                <GridView android:id="@+id/gridview"
android:layout_width="fill_parent"
                                android:layout_height="fill_parent"
android:numColumns="auto_fit"
                                android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
                                android:columnWidth="90dp"
android:stretchMode="columnWidth"
                                android:gravity="center" />

</LinearLayout>

Android CheckBox Example


CHECKBOX


Android checkbox is used to select more than one option at a time.
Example:  In an admission form we may need to select both diploma & BE in Graduate option.
For this we can use checkbox which will enable us to select multiple options.



SOURCE CODE [main.xml] is

<xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"

android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical">
                <CheckBox android:id="@+id/check1" 
android:layout_width="100px"
                                android:layout_height="wrap_content"
android:text="Android" />

Android - Custom ListView Example


CUSTOM LISTVIEW

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">

                <ListView android:id="@+id/ListView01"
android:layout_height="wrap_content"
                                android:layout_width="fill_parent">
</ListView>

</LinearLayout>

Show a context menu for long-clicks in an Android ListView


AN ACTIVITY WITH AN EXPANDING LISTVIEW

Creating a Simple ListView

If you have an activity that will only contain a single ListView control, you can derive your activity from the ListActivity instead of Activity. However, I think I might like to show some extra info below my ListView so I chose to have a separate ListView object. My activity layout (main.xml) looks like this:

<?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">
                <ListView android:id="@+id/ listview "
                                 android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_weight="1" />
</LinearLayout>

Android ListView OnClick Example


LISTVIEW ONCLICK
 
SOURCE CODE [main.xml] is 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android">
                <ListView android:id="@+id/listview"
android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />
</LinearLayout>

Android Search in ListView Example


SEARCH IN LISTVIEW


SOURCE CODE [main.xml] is


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical">
<EditText android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Search">
</EditText>

<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>

Android Simple ListView Example


SIMPLE LISTVIEW
 

SOURCE CODE [main.xml] is 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android">
                <ListView android:id="@+id/listview"
android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />
</LinearLayout>

Android - Structure of the Manifest.xml File

 STRUCTURE OF THE MANIFEST.XML FILE 

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

<manifest>
<uses-permission />
<permission />
<permission-tree />
<permission-group />
<instrumentation />
<uses-sdk />
<uses-configuration />
<uses-feature />
<supports-screens />
<compatible-screens />
<supports-gl-texture />

Popular Posts