Search This Blog

Showing posts with label TextView. Show all posts
Showing posts with label TextView. Show all posts

Tuesday, March 27, 2012

Display a Random Number in android on button click

To generate random number in Android, class java.util.Random can be used.

This class java.util.Random provides methods that generates pseudo-random numbers of different types, such as int, long, double, and float.

It support two public constructor:
Random() - Construct a random generator with the current time of day in milliseconds as the initial state.
Random(long seed) - Construct a random generator with the given seed as the initial state.


Put the following code in the main.xml.

<?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"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Generate Random number"
android:id="@+id/generate"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/generatenumber"
/>
</LinearLayout>


RandomNumber.java

import java.util.Random;

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

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

                        final Random myRandom = new Random();

                        Button buttonGenerate = (Button)findViewById(R.id.generate);
                        final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber);

                        buttonGenerate.setOnClickListener(new OnClickListener(){

                                 @Override
                                 public void onClick(View v) {
                                      // TODO Auto-generated method stub
                                      textGenerateNumber.setText(String.valueOf(myRandom.nextInt()));
                                  }
                      });
       }
}

Monday, March 26, 2012

Android Text to Speech

TextToSpeech is the great feature of Android. Text to Speech (TTS) which speaks the text in different languages usually selected by the user or you can also put the default user language for the TTS.
First of all make the xml file with the one EditText and Button. And make the following code working in your java file for the TTS. You need to implement the Interface of the TTS TextToSpeech.OnInitListener.

import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AndroidTextToSpeechActivity extends Activity implements
TextToSpeech.OnInitListener {
/** Called when the activity is first created. */

private TextToSpeech tts;
private Button btnSpeak;
private EditText txtText;

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

                       tts = new TextToSpeech(this, this);
                       btnSpeak = (Button) findViewById(R.id.btnSpeak);
                       txtText = (EditText) findViewById(R.id.txtText);

                       // button on click event
                       btnSpeak.setOnClickListener(new View.OnClickListener() {

                                            @Override
                                            public void onClick(View arg0) {
                                                             TTS();
                                             }

                        });
                }

           @Override
           public void onDestroy() {
                     // Don't forget to shutdown tts!
                     if (tts != null) {
                     tts.stop();
                     tts.shutdown();
            }
            super.onDestroy();
            }

            @Override
            public void onInit(int status) {

                           if (status == TextToSpeech.SUCCESS) {
                           int result = tts.setLanguage(Locale.US);
                           if (result == TextToSpeech.LANG_MISSING_DATA
                                                 || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                                                 Log.e("TTS", "This Language is not supported");
                            }

                            else
                           {
                                           btnSpeak.setEnabled(true);
                                           TTS();
                            }

                      }
                      else 
                      {
                                Log.e("TTS", "Initilization Failed!");
             }

        }

        private void TTS() {

                   String text = txtText.getText().toString();

                   tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
          }
}



You can change the language by the oneline code 

tts.setLanguage(Locale.CHINESE);
tts.setLanguage(Locale.GERMANY);

You can select the speed of the speaking via putting the setPitch() method.Default value is 1.0 of the pitch rate.You can select the pitch rate higher or lower according to the requirement.

tts.setPitch(0.6);
The speed rate can be set using setSpeechRate(). This also will take default of 1.0 value. You can double the speed rate by setting 2.0 or make half the speed level by setting 0.5.

tts.setSpeechRate(1.5);

Thursday, February 16, 2012

Read AndroidOS version info., using System.getProperty Method

Now this is the another class of reading the android Os version info with the getProperty Method.

Make an .xml file with the following code.


<?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="Android System:"
 />
<TextView
 android:id="@+id/SYSinfo"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 />
</LinearLayout>

Now make the java file for the getProperty method with the following code.



public class OSversion extends Activity{


@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.osversion);
TextView SYSinfo = (TextView) findViewById(R.id.SYSinfo);
    SYSinfo.setText(ReadSYSinfo());
}


private static StringBuffer SYSinfoBuffer;


private String ReadSYSinfo()
{
 SYSinfoBuffer = new StringBuffer();
 
 getProperty("os.name", "os.name", SYSinfoBuffer);
 getProperty("os.version", "os.version", SYSinfoBuffer);
 
 getProperty("java.vendor.url", "java.vendor.url", SYSinfoBuffer);
 getProperty("java.version", "java.version", SYSinfoBuffer);
 getProperty("java.class.path", "java.class.path", SYSinfoBuffer);
 getProperty("java.class.version", "java.class.version", SYSinfoBuffer);
 getProperty("java.vendor", "java.vendor", SYSinfoBuffer);
 getProperty("java.home", "java.home", SYSinfoBuffer);
 
 getProperty("user.name", "user.name", SYSinfoBuffer);
 getProperty("user.home", "user.home", SYSinfoBuffer);
 getProperty("user.dir", "user.dir", SYSinfoBuffer);
 
 return SYSinfoBuffer.toString();
}


private void getProperty(String name, String property, StringBuffer tBuffer)
{
 tBuffer.append(name);
 tBuffer.append(" : ");
 tBuffer.append(System.getProperty(property));
 tBuffer.append("\n");
}
}



Here is the output of the above code



How to Read OS/kernel Version

First of all make an .xml file and put the following code into it.


<?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:gravity="center_horizontal"
android:text="typicaljava.blogspot.com"
android:autoLink="web"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Android OS:"
/>
<TextView
android:id="@+id/OSinfo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>


Now make a JAVA file and put the following code below.



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


                 TextView OSinfo = (TextView) findViewById(R.id.OSinfo);
                 OSinfo.setText(ReadOSinfo());

        }



         private String ReadOSinfo()
        {
             ProcessBuilder cmd;
             String result="";

             try{

                        String[] args = {"/system/bin/cat", "/proc/version"};
                        cmd = new ProcessBuilder(args);

                           


                        Process process = cmd.start();

                        InputStream in = process.getInputStream();
                        byte[] re = new byte[1024];
                        while(in.read(re) != -1){
                        System.out.println(new String(re));
                        result = result + new String(re);
                }
                in.close();
           } 
           catch(IOException ex)
          {
               ex.printStackTrace();
           }
        return result;
     }
}


you'll get the following output.





Tuesday, February 14, 2012

Color Picker Dialog With Seekbar

This color picker dialog has sliders (SeekBars) and  EditTexts for red, green, blue and alpha values. It has a live preview of the color. It returns int values for R, G, B, A for easy use with Color.argb().

Make an .xml file main.xml and put the code below.


<?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" >
    <ImageView
android:id="@+id/color"
android:layout_width="fill_parent"
android:layout_height="60dip" />
    <Button 
    android:id="@+id/select"
    android:text="Select Color" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
</LinearLayout>


Now make an another .xml file named color_layout.xml and put the code below.



<?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="wrap_content" 
    android:id="@+id/main"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:minWidth="300dp">
    
    
<TextView
android:id="@+id/red_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="red" />
<LinearLayout
android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:gravity="center_vertical|left">
<SeekBar 
  android:id="@+id/red_bar"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:max="255"
  android:layout_weight="1"
  android:paddingLeft="7dp"
  android:paddingRight="7dp" />
<EditText
android:id="@+id/red_text"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:lines="1"
android:gravity="center_vertical|right"
android:maxLength="3"
android:inputType="number"
android:text="0"  />
</LinearLayout>


<TextView
android:id="@+id/green_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="green" />
<LinearLayout
android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:gravity="center_vertical|left">
<SeekBar 
  android:id="@+id/green_bar"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:max="255"
  android:layout_weight="1"
  android:paddingLeft="7dp"
  android:paddingRight="7dp" />
<EditText
android:id="@+id/green_text"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:lines="1"
android:gravity="center_vertical|right"
android:maxLength="3"
android:inputType="number"
android:text="0"  />
</LinearLayout>


<TextView
android:id="@+id/blue_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="blue" />
<LinearLayout
android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:gravity="center_vertical|left">
<SeekBar 
  android:id="@+id/blue_bar"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:max="255"
  android:layout_weight="1"
  android:paddingLeft="7dp"
  android:paddingRight="7dp" />
<EditText
android:id="@+id/blue_text"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:lines="1"
android:gravity="center_vertical|right"
android:maxLength="3"
android:inputType="number"
android:text="0"  />
</LinearLayout>


<TextView
android:id="@+id/alpha_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="alpha" />
<LinearLayout
android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:gravity="center_vertical|left">
<SeekBar 
  android:id="@+id/alpha_bar"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:max="255"
  android:progress="255"
  android:layout_weight="1"
  android:paddingLeft="7dp"
  android:paddingRight="7dp" />
<EditText
android:id="@+id/alpha_text"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:lines="1"
android:gravity="center_vertical|right"
android:maxLength="3"
android:inputType="number" 
android:text="255" 
/>
</LinearLayout>


<ImageView
android:id="@+id/color_preview"
android:layout_width="fill_parent"
android:layout_height="40dip" />

<LinearLayout
android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal"
    android:gravity="center_vertical|center_horizontal"
    android:layout_marginTop="20dp">
<Button 
  android:id="@+id/ok"
  android:layout_width="100dp"
  android:layout_height="wrap_content"
  android:text="OK" />
  <Button 
  android:id="@+id/cancel"
  android:layout_width="100dp"
  android:layout_height="wrap_content"
  android:text="Cancel" />

</LinearLayout>

</LinearLayout>




First of all make a java file named ColorPickerDialog and insert the following code into it.


public class ColorPickerDialog extends Dialog implements SeekBar.OnSeekBarChangeListener, TextWatcher, OnClickListener {
SeekBar   redBar;
EditText  redText;
SeekBar   greenBar;
EditText  greenText;
SeekBar   blueBar;
EditText  blueText;
SeekBar   alphaBar;
EditText  alphaText;
ImageView colorPreview;
Button    ok;
Button    cancel;
String    color;

    public interface OnColorChangedListener {
        void colorChanged(int a, int r, int g, int b);
    }


    private OnColorChangedListener mListener;




    public ColorPickerDialog(Context context, OnColorChangedListener listener, String color) {
        super(context);
        mListener = listener;
        this.color = color;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.color_layout);
        setTitle("Color Picker");
        
        redBar    = (SeekBar)  findViewById(R.id.red_bar);
redText   = (EditText) findViewById(R.id.red_text);
greenBar  = (SeekBar)  findViewById(R.id.green_bar);
greenText = (EditText) findViewById(R.id.green_text);
blueBar   = (SeekBar)  findViewById(R.id.blue_bar);
blueText  = (EditText) findViewById(R.id.blue_text);
alphaBar  = (SeekBar)  findViewById(R.id.alpha_bar);
alphaText = (EditText) findViewById(R.id.alpha_text);
ok         = (Button)   findViewById(R.id.ok);
cancel     = (Button)   findViewById(R.id.cancel);

colorPreview = (ImageView) findViewById(R.id.color_preview);

//set initial colors
String[] colorVal = color.split(",");
int a = Integer.parseInt(colorVal[0]);
int r = Integer.parseInt(colorVal[1]);
int g = Integer.parseInt(colorVal[2]);
int b = Integer.parseInt(colorVal[3]);

colorPreview.setBackgroundColor(Color.argb(a, r, g, b));
redBar.setProgress(r);
greenBar.setProgress(g);
blueBar.setProgress(b);
alphaBar.setProgress(a);

redText.setText(colorVal[1]);
greenText.setText(colorVal[2]);
blueText.setText(colorVal[3]);
alphaText.setText(colorVal[0]);

redBar.setOnSeekBarChangeListener(this);
greenBar.setOnSeekBarChangeListener(this);
blueBar.setOnSeekBarChangeListener(this);
alphaBar.setOnSeekBarChangeListener(this);

redText.addTextChangedListener(this);
greenText.addTextChangedListener(this);
blueText.addTextChangedListener(this);
alphaText.addTextChangedListener(this);


ok.setOnClickListener(this);
cancel.setOnClickListener(this);

setCancelable(false);




    }


    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(fromUser){
switch (seekBar.getId()) {
        case R.id.red_bar:  
        redText.setText(Integer.toString(progress));
        break;
        case R.id.green_bar:  
        greenText.setText(Integer.toString(progress));
        break;
        case R.id.blue_bar:  
        blueText.setText(Integer.toString(progress));
        break;
        case R.id.alpha_bar:  
        alphaText.setText(Integer.toString(progress));
        break;
       }
}

colorPreview.setBackgroundColor(Color.argb(alphaBar.getProgress(), redBar.getProgress(), greenBar.getProgress(), blueBar.getProgress()));


}


public void onStartTrackingTouch(SeekBar seekBar) {
}


public void onStopTrackingTouch(SeekBar seekBar) {
}


public void afterTextChanged(Editable arg0) {
if(Integer.parseInt(redText.getText().toString()) > 255)
redText.setText("255");

if(!redText.getText().toString().equals("")){
if(Integer.parseInt(redText.getText().toString()) > 255)
redText.setText("255");
redBar.setProgress(Integer.parseInt(redText.getText().toString()));
} else 
redBar.setProgress(0);


if(!greenText.getText().toString().equals("")){
if(Integer.parseInt(greenText.getText().toString()) > 255)
greenText.setText("255");
greenBar.setProgress(Integer.parseInt(greenText.getText().toString()));
} else 
greenBar.setProgress(0);


if(!blueText.getText().toString().equals("")){
if(Integer.parseInt(blueText.getText().toString()) > 255)
blueText.setText("255");
blueBar.setProgress(Integer.parseInt(blueText.getText().toString()));
}else 
blueBar.setProgress(0);


if(!alphaText.getText().toString().equals("")){
if(Integer.parseInt(alphaText.getText().toString()) > 255)
alphaText.setText("255");
alphaBar.setProgress(Integer.parseInt(alphaText.getText().toString()));
}else 
alphaBar.setProgress(0);


}


public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}


public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}



public void onClick(View v) {
switch (v.getId()) {
        case R.id.ok:  
        mListener.colorChanged(alphaBar.getProgress(), redBar.getProgress(), greenBar.getProgress(), blueBar.getProgress());
        dismiss();
        break;
        case R.id.cancel:  
        dismiss();
        break;
}

}
}


Now make a main java File named MyActivity with implementing the ColorPickerDialog.OnColorChangedListener. And put the code in it.



public class MyActivity extends Activity implements ColorPickerDialog.OnColorChangedListener {




String color = "255,255,000,000"; //alpha, red, green, blue
    
ImageView image;


    
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        image = (ImageView) findViewById(R.id.color);
        String[] colorVal = color.split(",");
        image.setBackgroundColor(Color.argb(Integer.parseInt(colorVal[0]),Integer.parseInt(colorVal[1]),Integer.parseInt(colorVal[2]),Integer.parseInt(colorVal[3])));
        
        Button btn = (Button) findViewById(R.id.select);
        btn.setOnClickListener(new View.OnClickListener() {
            
            public void onClick(View v) {
                new ColorPickerDialog(MyActivity.this, MyActivity.this, color).show();
            }
        });


    }


    public void colorChanged(int a, int r, int g, int b) {
    color = a + "," + r + "," + g + "," + b;
        image.setBackgroundColor(Color.argb(a,r,g,b));


    }


}






Monday, January 23, 2012

Get an Display Resolution of the Screen

android.util.DisplayMetrics is a structure describing general information about a display, such as its size, density, and font scaling.

To use android.util.DisplayMetrics to get resolution:

Create a dummy Android Application, add a TextView in main.xml to display the result.

<TextView
android:id="@+id/strScreenSize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>

Modify the .java file to read DisplayMetrics

 public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
     
            DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);
            String str_ScreenSize = "The Android Screen is: "
                        + dm.widthPixels
                        + " x "
                        + dm.heightPixels;

            TextView mScreenSize = (TextView) findViewById(R.id.strScreenSize);
            mScreenSize.setText(str_ScreenSize);
     }





Monday, January 16, 2012

How to call the asp .Net web service in android

First of all make sure that your web service is in the proper url and get that url with you.

Just like for example i use the web service of "http://www.webservicex.net/ConvertWeight.asmx" for converting the weights from one unit to another.

Now insert the external jar file of ksoap2 which can be downloaded from the following links

To make use of this library in a non-Maven project, follow the instructions in the Android Developer's Guide on how to Add an External Library to your project.

You will need to add a ksoap2-android and all required transitive dependencies to the build path. Luckily the Maven build of the project produces a nice bundle of all these jars in one big file.

The different version of these files are available at

http://code.google.com/p/ksoap2-android/source/browse/#svn/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/

To download a file from there, right click on "View raw file" and select "Save Link as" (this label differs for different browsers) and you will get the full jar downloaded.

The latest release artifact would be available at

http://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/2.6.0/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar

with a direct download url of
http://ksoap2-android.googlecode.com/svn/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/2.6.0/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar

Some users seem to experience download problems with IE. Just try a decent browser or download with a command line tool like wget
wget http://ksoap2-android.googlecode.com/svn/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/2.6.0/ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar

Now make the java file and insert the following in that code :


import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;


public class WebserActivity extends Activity {
private final String NAMESPACE = "http://www.webserviceX.NET/";
private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
private final String METHOD_NAME = "ConvertWeight";

/** Called when the activity is first created. */
@Override

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

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

String weight = "3700";
String fromUnit = "Grams";
String toUnit = "Kilograms";

PropertyInfo weightProp =new PropertyInfo();
weightProp.setName("Weight");
weightProp.setValue(weight);
weightProp.setType(double.class);
request.addProperty(weightProp);

PropertyInfo fromProp =new PropertyInfo();
fromProp.setName("FromUnit");
fromProp.setValue(fromUnit);
fromProp.setType(String.class);
request.addProperty(fromProp);

PropertyInfo toProp =new PropertyInfo();
toProp.setName("ToUnit");
toProp.setValue(toUnit);
toProp.setType(String.class);
request.addProperty(toProp);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {

    androidHttpTransport.call(SOAP_ACTION, envelope);
    SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
    Log.i("myApp", response.toString());
    
    TextView tv = new TextView(this);
     tv.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
     setContentView(tv);

        } catch (Exception e) {
                       e.printStackTrace();
        }

    }
}




Now make an xml file named main.xml and insert the following code into it :

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


And finally manifest file should be looks like this : 



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

    <application android:label="@string/app_name">
        <activity android:name=".WebserActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
 
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>