Basics for Using Radio Buttons + Buttons + Message Box

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby bjreddi » Thu Apr 03, 2008 1:42 pm

Hi,

I am a beginner to Android. I am just seeking help on Basic android examples.
I have tried the RadioButtons Tutorial which was posted by Plusminus.

When i tried to run the exercise i get the error in showAlert()

When i checked , the number of arguments which he has given in the showAlert(string,string,string,boolean) was only four. Where as it expected 5 arguments (string,int, string,string,boolean).

and i passed '0' as a argument in place of int. But the thrid expression in plusminus radio button code is not evaluating properly. and gives me error.

Can anyone guide me please.

-Jo
bjreddi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 03, 2008 1:24 pm

Top

Postby bjreddi » Thu Apr 03, 2008 1:49 pm

Hi,

I am a beginner to Android. I am just seeking help on Basic android examples.
I have tried the RadioButtons Tutorial which was posted by Plusminus.

When i tried to run the exercise i get the error in showAlert()

When i checked , the number of arguments which he has given in the showAlert(string,string,string,boolean) was only four. Where as it expected 5 arguments (string,int, string,string,boolean).

and i passed '0' as a argument in place of int. But the thrid expression in plusminus radio button code is not evaluating properly. and gives me error.

Can anyone guide me please.

-Jo
bjreddi
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Apr 03, 2008 1:24 pm

Postby Jesmiatka » Thu Apr 03, 2008 2:17 pm

This tutorial is based on M3 version of the SDK.
Currently we are at M5, which uses the Toast class for showing messages on the screen.

Example
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  Toast.makeText(Yourclass.class, "Your message", Toast.LENGTH_LONG).show();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Re: Basics for Using Radio Buttons + Buttons + Message Box

Postby sxjthefirst » Thu Apr 03, 2008 3:12 pm


showAlert( "Result",
(Exercise1.choice == Exercise1.ans) ? "Yes, you are right"
: "No, your answer is worgn ", "Close", true

You are using the wrong syntax. showAlert should be something like: showAlert(String, int, string, string, boolean);

The int being a icon resource id or 0 for no icon.
sxjthefirst
Developer
Developer
 
Posts: 36
Joined: Wed Mar 12, 2008 7:24 pm

Postby zehunter » Sun Jan 10, 2010 10:47 am

hi,

image of the tuto is not anymore visible. any possibility to fix it?
zehunter
Developer
Developer
 
Posts: 27
Joined: Sun Jan 10, 2010 10:45 am

Postby sampath_sl » Thu May 06, 2010 2:33 pm

Thanks to all of you who contributed to this thread. I survived theday thanks to it. :D

Keep up the good work guys!
sampath_sl
Developer
Developer
 
Posts: 35
Joined: Sun Apr 11, 2010 4:45 pm
Location: Colombo

Top

Re: Basics for Using Radio Buttons + Buttons + Message Box

Postby Dhr » Wed Aug 25, 2010 7:23 am

Hello plusminus and everyone,

Myself is Dhr.
i m new in this Android World.

I made one application. The application is basically based on browsing a text file from eclipse.

In that I create a page which contains one button.
the user press this button and then after the text file which is in the eclipse is open and the user can read that file.

Here is my code:
browse.java
Code: Select all
package abc.browsing_file;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

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

public class browse extends Activity {
    private static final Object Button01 = null;

   /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Button button = (Button)findViewById(R.id.Button01);
        button.getId();
        TextView helloTxt = (TextView)findViewById(R.id.hellotxt);
        helloTxt.setText(readText());
    }
   
    public void myClickHandler(View v)
    {
       if(v.equals(((View) Button01).getId()))
       {
          readText();
       }
    }

   private String readText()
    {
       InputStream inputStream = getResources().openRawResource(R.raw.hello);
       
       ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
       
       int i;
       try{
          i= inputStream.read();
          while (i != -1)
          {
               byteArrayOutputStream.write(i);
                 i = inputStream.read();
          }
          inputStream.close();
       }
       catch(IOException e){
          e.printStackTrace();
       }
       return byteArrayOutputStream.toString();
    }
}


main.xml
Code: Select all
<?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"
    />
<TextView 
   android:id="@+id/hellotxt"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="22px"
    />
<Button
   android:id="@+id/Button01"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:autoLink="phone"
   android:text="Browse" android:onClick="@string/buttonHandler">
   </Button>
</LinearLayout>



strings.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, browse!</string>
    <string name="app_name">browsing_file</string>
<string name="buttonHandler"></string>
</resources>


hello.txt
Code: Select all
hello..
welcome to Android Application.



Can anyone has knoeledge how ti solve it??

Please please .. Help mee..

Thanks/Regards,
Dhr
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Re: Basics for Using Radio Buttons + Buttons + Message Box

Postby Dhr » Wed Aug 25, 2010 9:05 am

Hello plusminus and everyone,

Myself is Dhr.
i m new in this Android World.

I made one application. The application is basically based on browsing a text file from eclipse.

In that I create a page which contains one button.
the user press this button and then after the text file which is in the eclipse is open and the user can read that file.

Here is my code:
browse.java
Code: Select all
package abc.browsing_file;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

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

public class browse extends Activity {
    private static final Object Button01 = null;

   /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Button button = (Button)findViewById(R.id.Button01);
        button.getId();
        TextView helloTxt = (TextView)findViewById(R.id.hellotxt);
        helloTxt.setText(readText());
    }
   
    public void myClickHandler(View v)
    {
       if(v.equals(((View) Button01).getId()))
       {
          readText();
       }
    }

   private String readText()
    {
       InputStream inputStream = getResources().openRawResource(R.raw.hello);
       
       ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
       
       int i;
       try{
          i= inputStream.read();
          while (i != -1)
          {
               byteArrayOutputStream.write(i);
                 i = inputStream.read();
          }
          inputStream.close();
       }
       catch(IOException e){
          e.printStackTrace();
       }
       return byteArrayOutputStream.toString();
    }
}


main.xml
Code: Select all
<?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"
    />
<TextView 
   android:id="@+id/hellotxt"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="22px"
    />
<Button
   android:id="@+id/Button01"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:autoLink="phone"
   android:text="Browse" android:onClick="@string/buttonHandler">
   </Button>
</LinearLayout>



strings.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, browse!</string>
    <string name="app_name">browsing_file</string>
<string name="buttonHandler"></string>
</resources>


hello.txt
Code: Select all
hello..
welcome to Android Application.



Can anyone has knoeledge how ti solve it??

Please please .. Help mee..

Thanks/Regards,
Dhr
User avatar
Dhr
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Aug 19, 2010 11:59 am
Location: Ahd, Gujarat, India

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests