Pages

Friday, March 29, 2013

tab control

http://www.edumobile.org/android/android-beginner-tutorials/tab-control/

and
http://www.codeproject.com/Articles/107693/Tabbed-Applications-in-Android

and
http://kandroid.wordpress.com/2011/05/28/tabview-part-1-simple-tab-control-in-android/

SAME activity----
XML

<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">
         
    <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
           
            />
    <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
   <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/taba1"
    android:orientation="vertical"
    android:paddingTop="60px"
     >
    

     <Button
         android:id="@+id/button2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Button" />

     <Button
         android:id="@+id/button1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Button" />
    
     </LinearLayout>
     
     <LinearLayout
     android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/taba2"
    android:orientation="vertical"
    android:paddingTop="60px"
     >
    

     <Button
         android:id="@+id/button3"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Button" />
   
     </LinearLayout>
     </FrameLayout>
</TabHost>


java..


import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);
       TabHost tabHost = getTabHost();    


TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.taba1);
spec1.setIndicator("Tab 1");

TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(R.id.taba2);



tabHost.addTab(spec1);
tabHost.addTab(spec2);

}



}

.................
new activites

  tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("TEXT").setContent(new Intent(this, OptionsActivity.class)));

//        tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("LIST").setContent(new Intent(this, et.class)));
//        tabHost.setCurrentTab(0);


Add home button in title bar

1.http://pastebin.com/GiyLvmsj
2.http://www.londatiga.net/it/how-to-create-custom-window-title-in-android/


Set background color of title bar



Set background color of title bar

Wednesday, March 20, 2013

Tuesday, March 19, 2013

Monday, March 18, 2013

List view data from php

two xmls
activity_main.xml

Spinner data from MySQL PHP


Step 1: Open Eclipse :P 

Step 2 : Add the following Code to activity_main.xml :

PHP scripts Select all


database -test
table category
columns-category_id , category


<?php
//connect to mySQL
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
//Select database
mysql_select_db("test",$con);
//query table
$sql=mysql_query("SELECT * FROM category ORDER BY `category`.`category` ASC");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close($con);
?>

PHP scripts JSON android login



database: mobiledb
table androidlogin
columns - id,user,pass
<?php

//Create fields for database , server , username ,password, database
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbdb = "mobiledb";

//Connect to mySQL
$connect = mysql_connect($dbhost , $dbuser , $dbpass)
or die("connection error");

//select the database
mysql_select_db($dbdb)or die("database selection error");

//retrieve the login details via post
$username = $_POST['username'];
$password = $_POST['password'];

//query the table android login
$query  = mysql_query("SELECT * FROM androidlogin WHERE user = '$username' AND

pass = '$password'");

//check if there is any results returned
$num = mysql_num_row($query);

//if a record was found matching the details entered in the query
if($num==1)
{
//create a while loop that places the returned data into an array
while($list = mysql_fetch_assoc($query))
{
//store the returned data into variable
$output = $list;

//encode the data in JSON format
echo json_encode($output);
}

//close the connection
mysql_close();

}
?>




or 

<?php

//Create fields for database , server , username ,password, database
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbdb = "mobiledb";

//Connect to mySQL
$connect = mysql_connect($dbhost , $dbuser , $dbpass)
or die("connection error");

//select the database
mysql_select_db($dbdb)or die("database selection error");



//retrieve the login details via post
$username = $_POST['username'];
$password = $_POST['password'];

//query the table android login
$query  = mysql_query("SELECT * FROM androidlogin WHERE user = '$username' AND pass = '$password'");


//create a while loop that places the returned data into an array
while($list = mysql_fetch_assoc($query))
{
//store the returned data into variable
$output[] = $list;

//encode the data in JSON format
echo json_encode($output);
}

//close the connection
mysql_close($connect);

?>


Sunday, March 17, 2013

Simple AsyncTask

XML
Don't forget to Add internet permission.


Retrieve tweets from twitter using button and JSON


XML
Don't forget to add Internet Permission. 


Retrieve all tweets from twitter using json

Progress dialogue Added 

Don't forget to add Internet Permission. 
XML
Same as previous article

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


    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/tvJson"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tweets:" />

        </LinearLayout>
    </ScrollView>

</LinearLayout>


Retrieve last tweet from twitter using JSON

XML
Don't forget to add Internet Permission. 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

   

    <Button
        android:id="@+id/btnShowTweets"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="showTweets"
        android:text="Show Tweets!" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/tvJson"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Tweets:" />

        </LinearLayout>
    </ScrollView>

</LinearLayout>