Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Android Development

  1. #1
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default Android Development

    SIMPLE ADDING MACHINE (Beginner)
    Tutorial is for people who already have eclipse installed and the SDK.
    If not go here for info.
    STEP1
    Start up eclipse and start a new android project.
    You can name your project add.
    Then below that youll see properties
    APPliCATION NAME: add
    PACKAGE NAME:com.add
    CREATE ACTIVITY:add
    STEP2
    In the res folder of the package explorer window youll see a layout folder. Enter a paste the following code into the main.xml file. You'll be pasting everything thus overwriting the previous code.

    LAYOUT
    Edit the XML file by cutting this code into it.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
    android:id="@+id/widget41"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ff66ffff"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <Button
    android:id="@+id/calBtn"
    android:layout_width="96px"
    android:layout_height="34px"
    android:background="#ff0099ff"
    android:text="Calculate"
    android:textSize="18sp"
    android:layout_x="104px"
    android:layout_y="259px"
    >
    </Button>
    <EditText
    android:id="@+id/field1"
    android:layout_width="167px"
    android:layout_height="50px"
    android:textSize="18sp"
    android:layout_x="71px"
    android:layout_y="45px"
    >
    </EditText>
    <EditText
    android:id="@+id/field2"
    android:layout_width="164px"
    android:layout_height="55px"
    android:textSize="18sp"
    android:layout_x="74px"
    android:layout_y="183px"
    >
    </EditText>
    <TextView
    android:id="@+id/widget44"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:text="="
    android:textSize="25sp"
    android:textStyle="bold"
    android:layout_x="133px"
    android:layout_y="129px"
    >
    </TextView>
    <TextView
    android:id="@+id/answer"
    android:layout_width="99px"
    android:layout_height="29px"
    android:textSize="19sp"
    android:layout_x="124px"
    android:layout_y="330px"
    android:textColor="#ff000000">
    </TextView>
    <TextView
    android:id="@+id/widget34"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:text="+"
    android:layout_x="63px"
    android:layout_y="128px"
    >
    </TextView>
    <TextView
    android:id="@+id/widget35"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="RESULT:->"
    android:textSize="18sp"
    android:textColor="#ff000000"
    android:layout_x="26px"
    android:layout_y="333px"
    >
    </TextView>
    <TextView
    android:id="@+id/widget36"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:text="Operations:"
    android:textSize="16sp"
    android:layout_x="192px"
    android:layout_y="81px"
    >
    </TextView>
    <RadioButton
    android:id="@+id/plus"
    android:layout_width="wrap_content"
    android:layout_height="41px"
    android:text=" +"
    android:layout_x="32px"
    android:layout_y="124px"
    >
    </RadioButton>
    <RadioButton
    android:id="@+id/Mul"
    android:layout_width="96px"
    android:layout_height="wrap_content"
    android:text=" *"
    android:layout_x="100px"
    android:layout_y="122px"
    >
    </RadioButton>
    <RadioButton
    android:id="@+id/minus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" -"
    android:layout_x="170px"
    android:layout_y="120px"
    >
    </RadioButton>
    <RadioButton
    android:id="@+id/div"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" /"
    android:layout_x="237px"
    android:layout_y="120px"
    >
    </RadioButton>
    <ImageView
    android:id="@+id/widget41"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:layout_x="237px"
    android:layout_y="38px"
    >
    </ImageView>
    <TextView
    android:id="@+id/widget42"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:textStyle="bold|italic"
    android:layout_x="102px"
    android:layout_y="9px" android:textColor="#ff000000" android:text="CALCULATE">
    </TextView>
    </AbsoluteLayout>
    The layout file, is the file that defines the actual interface of the application.

    STEP3
    In the src folder paste the following code below in the source file.
    CODE
    Code:
    /*Date:July 12 , 2010
     *Program Developed by Andre Piper aka mobile_fan_2k5.
     *email:andrepiper@gmail.com
     */
    package com.Calculate;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.*;
     
    public  class Calculate extends Activity implements OnClickListener  
    	{
    	TextView answer;
    	Button calculate;
    	TextView number1,number2;
    	RadioButton plus,minus,divide,multi;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            //------------
            plus=(RadioButton)this.findViewById((R.id.plus));
            minus=(RadioButton)this.findViewById((R.id.minus));
            divide=(RadioButton)this.findViewById((R.id.div));
            multi=(RadioButton)this.findViewById((R.id.Mul));
            answer=(TextView)this.findViewById((R.id.answer));
            number1=(TextView)this.findViewById((R.id.field1));
            number2=(TextView)this.findViewById((R.id.field2));
            calculate=(Button)this.findViewById(R.id.calBtn);
            calculate.setOnClickListener(this);
    
        	
          
        }
        //-----BUTTON PRESSED
        public void onClick(View v){
        	if(calculate.isPressed())
        	{
        		if(plus.isChecked())
            	{
            	plusFunc();
            	plus.setChecked(false);//uncheck button
            	number1.setText("");
            	number2.setText("");
            	}
            	//------------
            	if(minus.isChecked())
            	{
            	minusFunc();
            	minus.setChecked(false);//uncheck button
            	number1.setText("");
            	number2.setText("");
            	}
            	//-----------
            	if(divide.isChecked())
            	{
            	divideFunc();
            	divide.setChecked(false);//uncheck button
            	number1.setText("");
            	number2.setText("");
            	}
            	//--------------
            	if(multi.isChecked())
            	{
            	multiFunc();
            	multi.setChecked(false);//uncheck button
            	number1.setText("");
            	number2.setText("");
            	}
        	}
        }
        //--------------------Doing the actual adding,minus,divide and multiplaication
        protected void plusFunc()
        {
        	double value1=Double.parseDouble(number1.getText().toString());
        	double value2=Double.parseDouble(number2.getText().toString());
        	double answer2=value1+value2;
        	answer.setText(Double.toString(answer2));
        }
        protected void minusFunc()
        {
        	double value1=Double.parseDouble(number1.getText().toString());
        	double value2=Double.parseDouble(number2.getText().toString());
        	double answer2=value1-value2;
        	answer.setText(Double.toString(answer2));
        }
        protected void divideFunc()
        {
        	double value1=Double.parseDouble(number1.getText().toString());
        	double value2=Double.parseDouble(number2.getText().toString());
        	
        	double answer2=value1/value2;
        	answer.setText(Double.toString(answer2));
        }
        protected void multiFunc()
        {
        	double value1=Double.parseDouble(number1.getText().toString());
        	double value2=Double.parseDouble(number2.getText().toString());
        	double answer2=value1*value2;
        	answer.setText(Double.toString(answer2));
        }
        
    }
    STEP4
    Just run and you have an android app.
    For a better tutorial check android sdk and android resources.
    Last edited by mobile_fan_2k5; Jul 14, 2010 at 12:59 PM.
    Pc= Hp dv6t

  2. #2
    Join Date
    Jun 2002
    Posts
    641
    Rep Power
    0

    Default

    Respect due, hey mobile_fan_2k5, can you provide screenshot(s) ?
    Most people are visual and like to see what the end result will look like.

    Screenshots go hand-in-hand with sample code
    I recommend Ubuntu

  3. #3
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    I didnt have my claro 3g connection so hence the crappy tutorial.
    source code


    XML(layout)


    SImulator Interface


    App in action
    Last edited by mobile_fan_2k5; Jul 18, 2010 at 08:42 PM.
    Pc= Hp dv6t

  4. #4
    Join Date
    Feb 2007
    Posts
    4,170
    Rep Power
    0

    Default

    Looking good....not bad....Cant wait to get to this stage....
    Sony Vaio Laptop
    Windows 8 Pro 64-Bit
    320Gb Hard Drive, 4Gb RAM, BluRay DVD Drive

  5. #5
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default Intermediate Droid Development

    ---------------------PHP+MYSQL + Android= Sweet-----------------------------
    This topic is so problematic. I'm doing a project now that will need database access. This is a tutorial to access remote database with an android...

    Things you'll need
    1... PHP host with MYSQL
    2... And you'll need SDK with handset or Emulator
    3... Basic knowledge of Web Host panel and Php and SQL
    -------------------PHP CODE--------------
    Code:
    <?php
    $host="localhost"; // Host name
    $username=""; // Mysql username
    $password=""; // Mysql password
    $db_name=""; // Database name
    $tbl_name=""; // Table name
    
    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    
    // username and password sent from form
    $myusername=$_POST['username'];
    $mypassword=$_POST['password'];
    
    // To protect MySQL injection
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    
    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){
    echo "true";
    }
    else {
    echo "Login Failed";
    }
    ?>


    ---------------------------------------------
    .............STEP 1...................

    .............STEP 2...................

    .............STEP 3...................

    .............STEP 4...................

    .............STEP 5...................


    .............STEP 6...................


    CODE
    Code:
    <?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:id="@+id/TextView01"
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:text="Username" />
    
    
        <EditText
            android:id="@+id/username"
            android:layout_width="255dp"
            android:layout_height="wrap_content" >
    
            <requestFocus />
        </EditText>
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="110dp"
            android:layout_height="wrap_content"
            android:text="Password" />
    
    
        <EditText
            android:id="@+id/Password"
            android:layout_width="259dp"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
    
        <Button
            android:id="@+id/loginBtn"
            android:layout_width="123dp"
            android:layout_height="wrap_content"
            android:text="Login" />
    
    
        <TextView
            android:id="@+id/status"
            android:layout_width="140dp"
            android:layout_height="wrap_content"/>
    
    </LinearLayout>
    Last edited by mobile_fan_2k5; Dec 17, 2011 at 04:13 PM.
    Pc= Hp dv6t

  6. #6
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    .............STEP 7...................

    .............STEP 8...................

    ---------------------

    Then you'll insert this code
    Code:
    package com.techjamaica.php_Droid;
    
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class Php_DroidActivity extends Activity implements OnClickListener {
    	
    	Button ok,back,exit;
    	 TextView result;
    	 
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            // Login button clicked
            ok = (Button)findViewById(R.id.loginBtn);
            ok.setOnClickListener(this);
             
            result = (TextView)findViewById(R.id.status);
        }
        
        //----------------Function to post login and communicate with mysql server----------
        public void postLoginData() {
        	// Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
             
            /* login.php returns true if username and password is equal to saranga */
            HttpPost httppost = new HttpPost("http://yourwebsite.com/test.php");
     
            try {
            	
                // Add user name and password
             EditText uname = (EditText)findViewById(R.id.username);
             String username = uname.getText().toString();
     
             EditText pword = (EditText)findViewById(R.id.Password);
             String password = pword.getText().toString();
              
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("username", username));
                nameValuePairs.add(new BasicNameValuePair("password", password));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
     
                // Execute HTTP Post Request
                //---------------
    
                Log.w("Techjamaica", "Execute HTTP Post Request");
                HttpResponse response = httpclient.execute(httppost);
                 
                String str = inputStreamToString(response.getEntity().getContent()).toString();
                Log.w("Techjamaica", str);
                
                //-----------------------
    
                
                if(str.toString().equalsIgnoreCase("true"))
                {
    	            
                 Log.w("Techjamaica", "TRUE");
                 result.setText("Login successful");
                 uname.setText("");
                 pword.setText("");
                 
    
                }else
                {
                 Log.w("Techjamaica", "FALSE");
                 //result.setText(str);
                 
                }
                
     
            } catch (ClientProtocolException e) {
             e.printStackTrace();
            } catch (IOException e) {
             e.printStackTrace();
            }
            
        } //-----end of postdata()
    
        private StringBuilder inputStreamToString(InputStream is) {
            String line = "";
            StringBuilder total = new StringBuilder();
            // Wrap a BufferedReader around the InputStream
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            // Read response until the end
            try {
             while ((line = rd.readLine()) != null) { 
               total.append(line); 
             }
            } catch (IOException e) {
             e.printStackTrace();
            }
            // Return full string
            return total;
           }
        
    	public void onClick(View v) {
    		// TODO Auto-generated method stub
    		postLoginData();
    	}
    }
    .............STEP 9...................
    Based on user input it will give two message.. Successful or failed

    or
    Last edited by mobile_fan_2k5; Dec 17, 2011 at 04:11 PM.
    Pc= Hp dv6t

  7. #7
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    My version that I use....

    So you can try it..

    1... After successful login goes to another view.
    2... UI Dialog to show that app is communicating with server

    3... If failed error Dialog and ask to try again..



    Additional References to Help out..
    http://developer.android.com/guide/t...ml#AlertDialog
    http://developer.android.com/referen.../Activity.html
    ----------------------------------------------------------------------------------------------------------------------------------

    Download here
    Last edited by mobile_fan_2k5; Dec 17, 2011 at 04:36 PM.
    Pc= Hp dv6t

  8. #8
    Join Date
    Jul 2009
    Posts
    3,682
    Rep Power
    11

    Default

    u going hard ova hear peeps keep up the good work if u guys need testers for anything just send me a pm or shout me on the num in ma sig...i wish i was more programming oriented to i could offer more than that

  9. #9
    Join Date
    Dec 2005
    Posts
    1,951
    Rep Power
    0

    Default

    will do have a health management application that I'm developing so I will keep you in mind...
    Pc= Hp dv6t

  10. #10
    Join Date
    Jul 2009
    Posts
    3,682
    Rep Power
    11

    Default

    Quote Originally Posted by mobile_fan_2k5 View Post
    will do have a health management application that I'm developing so I will keep you in mind...
    yeah man kool......whats it about though maybe we can give some pointers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •