Thursday 31 January 2013

ListView Demo - Passing own Style

Demo:



1.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:background="#5F04B4"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/lvList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" />

</LinearLayout>


2.style.xml:


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
      android:gravity="center_vertical"
    android:textColor="#ffffff"
    android:textSize="20dp" />


3.Activity:


package com.venky.listviewpassingownstyle;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListViewpassingOwnStyleActivity extends Activity {
      /** Called when the activity is first created. */

      ListView lvList;

      String[] Languages = { "Telugu", "English", "Hindi", "Tamil", "Kanada",
                  "Urdu", "Punjabi", "etc" };

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            lvList = (ListView) findViewById(R.id.lvList);

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                        R.layout.style, Languages);

            lvList.setAdapter(adapter);
      }
}

4)Download this Project Click Here 
 

ListView Demo

Demo:
 


1.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:background="#5F04B4"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

</LinearLayout>

2.Activity:
package com.venky.listviewdemo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListViewDemoActivity extends Activity {
      /** Called when the activity is first created. */

      ListView listview;

      String[] Languages = { "Telugu", "English", "Hindi", "Tamil", "Kanada",
                  "Urdu", "Punjabi", "etc" };

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            listview = (ListView) findViewById(R.id.listView1);

            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                        ListViewDemoActivity.this, android.R.layout.simple_list_item_1,
                        Languages);

            listview.setAdapter(arrayAdapter);
      }
}


3)Download this Project Click Here 
 

Wednesday 30 January 2013

AutoCompleteTextView - Passing own style

Demo:




1)MainActivity.java:

package com.venky.actv;

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

public class ACTVpassingOwnStyle extends Activity {
      /** Called when the activity is first created. */
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

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

            String[] subjects = { "Android", "AndroidBooks", "AndroidGames",
                        "AndroidTheames", "AndroidMobiles", "AndroidTablets",
                        "AndroidDeveloper", "AndroidSoftware" };

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                        R.layout.style, subjects);

            auto.setAdapter(adapter);

      }

}

  
2) 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:background="#5F04B4"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:text="AutoComplete TextView"
        android:textSize="15dp"
        android:textStyle="bold" />

    <AutoCompleteTextView
        android:id="@+id/auto"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:completionThreshold="2"
        android:popupBackground="#000000"
        android:textColor="#FF0000" />

</LinearLayout>


3)style.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#5F04B4"
    android:text="MyText"
    android:textColor="@android:color/black"
    android:textSize="20dp" />

4) Download this Project Click Here

Monday 28 January 2013

Vertical Tabs in Android

Screen Shots:



1. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:baselineAligned="false"
        android:orientation="horizontal" >

        <FrameLayout
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.3" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:visibility="invisible" />

            <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" >

                    <Button
                        android:id="@+id/artist_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab1" />

                    <Button
                        android:id="@+id/album_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab2" />

                    <Button
                        android:id="@+id/song_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab3" />

                    <Button
                        android:id="@+id/tab4_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab4" />

                    <Button
                        android:id="@+id/tab5_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab5" />

                    <Button
                        android:id="@+id/tab6_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab6" />

                    <Button
                        android:id="@+id/tab7_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab7" />

                    <Button
                        android:id="@+id/tab8_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab8" />

                    <Button
                        android:id="@+id/tab9_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab9" />


                    <Button
                        android:id="@+id/tab10_id"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:onClick="tabHandler"
                        android:text="Tab10" />
                </LinearLayout>
            </ScrollView>
        </FrameLayout>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="0.7" />
    </LinearLayout>

</TabHost>


2. MainActivity
public class MainActivity extends TabActivity {

          Button artistButton, songButton, videosButton;

          TabHost tabHost;

          @Override
          public void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                   setContentView(R.layout.activity_main);

                   // Buttons referencing
                   artistButton = (Button) findViewById(R.id.artist_id);
                   songButton = (Button) findViewById(R.id.song_id);
                   videosButton = (Button) findViewById(R.id.album_id);

                   // getting TabHost
                   tabHost = getTabHost();

                   // Tab for Photos
                   TabSpec photospec = tabHost.newTabSpec("Photos");

                   // setting indicator
                   photospec.setIndicator("Photos");
                   Intent photosIntent = new Intent(this, Tab1Activity.class);
                    photospec.setContent(photosIntent);

                   // Tab for Songs
                   TabSpec songspec = tabHost.newTabSpec("Songs");
                   songspec.setIndicator("Songs");
                   Intent songsIntent = new Intent(this, Tab2Activity.class);
                   songspec.setContent(songsIntent);

                   // Tab for Videos
                   TabSpec videospec = tabHost.newTabSpec("Videos");
                   videospec.setIndicator("Videos");
                   Intent videosIntent = new Intent(this, Tab3Activity.class);
                   videospec.setContent(videosIntent);

                   // Adding all TabSpec to TabHost
                   tabHost.addTab(photospec); // Adding photos tab
                   tabHost.addTab(songspec); // Adding songs tab
                   tabHost.addTab(videospec); // Adding videos tab

          }

          public void tabHandler(View target) {
                   artistButton.setSelected(false);
                   videosButton.setSelected(false);
                   songButton.setSelected(false);
                   if (target.getId() == R.id.artist_id) {
                             tabHost.setCurrentTab(0);
                             artistButton.setSelected(true);
                   } else if (target.getId() == R.id.album_id) {
                             tabHost.setCurrentTab(1);
                             videosButton.setSelected(true);
                   } else if (target.getId() == R.id.song_id) {
                             tabHost.setCurrentTab(2);
                             songButton.setSelected(true);
                   }
          };

}


3.1. Tab1Activity
public class Tab1Activity extends Activity {

          @Override
          public void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                   setContentView(R.layout.tab1_view);

          }

}

3.2. tab1_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0000ff" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Tab 1"
        android:textAllCaps="true"
        android:textColor="#ffffff"
        android:textSize="50dp"
        android:textStyle="bold" />

</RelativeLayout>


4.1. Tab2Activity
public class Tab2Activity extends Activity {
          /** Called when the activity is first created. */

          @Override
          public void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                   setContentView(R.layout.tab2_view);

          }

}

4.2. tab2_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00ffff" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Tab 2"
        android:textAllCaps="true"
        android:textColor="#ffffff"
        android:textSize="50dp"
        android:textStyle="bold" />

</RelativeLayout>


5.1. Tab3Activity
public class Tab3Activity extends Activity {

          @Override
          public void onCreate(Bundle savedInstanceState) {
                   super.onCreate(savedInstanceState);
                   setContentView(R.layout.tab3_view);

          }

}

5.2. tab3_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff00ff" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Tab 3"
        android:textAllCaps="true"
        android:textColor="#ffffff"
        android:textSize="50dp"
        android:textStyle="bold" />

</RelativeLayout>


6. mainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.venkat.verticaltabsdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".Tab1Activity" />
        <activity android:name=".Tab2Activity" />
        <activity android:name=".Tab3Activity" />
    </application>

</manifest>

************************************

    Download Full Source Code HERE

************************************