XML Layouting - The anddev.org BoardSearcher

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

Postby Stephen.Ada » Sat Apr 12, 2008 4:13 pm

Hello +-
thx for your tut , I write the code not copy paste, it runs without errors . But there is something I wonder is that when i type some words in the edit text, and press ok button, what would happen ? In my emulator, it happened nothing, just the cursor stay flashing without any other changes. should it start the browser, and search the content i type in the edittext from your website? because of low configuration of my computer? :?: :?:
Stephen.Ada
Junior Developer
Junior Developer
 
Posts: 10
Joined: Mon Mar 10, 2008 3:18 pm

Top

Postby beeshop » Wed Sep 03, 2008 8:13 am

Hi there, nice post here.
I want to to a different aproach. I want to hav a xml with some components, buttons, inpu/edit Text etc, and then call them as I want. For instance, I want to build a dynamical generated GUi, so I receive a file parse it and call the R.layout file, but only some component. I want to call each component, maybe I have on or to that aren't called and then set the text size, etc.
After that I must set the contentView.
But then I cannot do it with more than one component. How do I do this?

Set a contentview that is empty? Is there any place where I can read about implementing UI components without the xml? I'll be glad for an awnser, cause it is driving me a little bit nuts.
beeshop
Freshman
Freshman
 
Posts: 5
Joined: Tue Aug 12, 2008 9:13 am

Postby Artur79 » Tue Sep 30, 2008 11:10 am

beeshop, here is a small bit of code, from google android page, about your query
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.android.hello;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.TextView;
  6.  
  7. public class HelloAndroid extends Activity {
  8.    /** Called when the activity is first created. */
  9.    @Override
  10.    public void onCreate(Bundle savedInstanceState) {
  11.        super.onCreate(savedInstanceState);
  12.        TextView tv = new TextView(this);
  13.        tv.setText("Hello, Android");
  14.        setContentView(tv);
  15.    }
  16. }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

http://code.google.com/android/intro/he ... #upgrading
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby anddeveloper » Wed Oct 08, 2008 10:54 pm

Great tutorial. Thanks.

I just used the same XML layout on the latest version emulator, but the layout does not appear correctly. See the attached screenshot. The view items appear to be overlapping. What am I doing wrong?

This is what my XML looks like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.                android:layout_width="fill_parent"
  4.  
  5.                android:layout_height="fill_parent"
  6.  
  7.                android:background="@drawable/icon"
  8.  
  9.                android:padding="10px">
  10.  
  11.  
  12.  
  13.     <TextView id="@+id/main_label"
  14.  
  15.              android:layout_width="fill_parent"
  16.  
  17.              android:layout_height="wrap_content"
  18.  
  19.              android:text="anddev.org - boardsearcher"
  20.  
  21.              android:textStyle="bold" />
  22.  
  23.              
  24.  
  25.     <TextView id="@+id/info_label"
  26.  
  27.              android:layout_width="fill_parent"
  28.  
  29.              android:layout_height="wrap_content"
  30.  
  31.              android:text="Type search-keyword here:"
  32.  
  33.              android:layout_below="@id/main_label" />
  34.  
  35.  
  36.  
  37.     <EditText id="@+id/keyword_entry"
  38.  
  39.              android:layout_width="fill_parent"
  40.  
  41.              android:layout_height="wrap_content"
  42.  
  43.              android:background="@android:drawable/editbox_background"
  44.  
  45.              android:layout_below="@id/info_label"
  46.  
  47.              android:singleLine="true" />
  48.  
  49.  
  50.  
  51.     <Button id="@+id/ok_button"
  52.  
  53.            android:layout_width="wrap_content"
  54.  
  55.            android:layout_height="wrap_content"
  56.  
  57.            android:layout_below="@id/keyword_entry"
  58.  
  59.            android:layout_alignParentRight="true"
  60.  
  61.            android:layout_marginLeft="10px"
  62.  
  63.            android:text="OK" />
  64.  
  65. </RelativeLayout>
Parsed in 0.015 seconds, using GeSHi 1.0.8.4
Attachments
device.png
device.png (32.08 KiB) Viewed 3405 times
anddeveloper
Freshman
Freshman
 
Posts: 2
Joined: Wed Oct 08, 2008 10:40 pm

Postby plusminus » Thu Oct 09, 2008 12:11 am

Hello anddeveloper,

thats (very probably) because the xml-definitions changed since I made this tutorial:

where it was before:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. id="@+id/main_label"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

it has to be
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:id="@+id/main_label"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


The reason why it was overlapping was the following. In this xml-view:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.     <TextView id="@+id/info_label"
  2.  
  3.              android:layout_width="fill_parent"
  4.  
  5.              android:layout_height="wrap_content"
  6.  
  7.              android:text="Type search-keyword here:"
  8.  
  9.              android:layout_below="@id/main_label" />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

We have the following line:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.           android:layout_below="@id/main_label"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

which refers to an ID that was not correctly defined for the above reason.

If theres still an issue after this, let me know.

Best Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby anddeveloper » Thu Oct 09, 2008 12:52 am

Thanks! That was exactly the problem.
anddeveloper
Freshman
Freshman
 
Posts: 2
Joined: Wed Oct 08, 2008 10:40 pm

Top

Postby adonnini » Thu Oct 16, 2008 2:11 am

Hello,

I am new to this board and Android. Probably, I am missing something obvious but I cannot seem to make the "XML Layouting" application compile as it appears that "showAlert" is no longer supported causing an error in

showAlert("Error", 0, "Couldn't find the 'keyword_entry'"
+ "EditView in main.xml", "Damn it... OK", false);

What am I overlooking?

Thanks.

Alex
adonnini
Freshman
Freshman
 
Posts: 3
Joined: Thu Oct 16, 2008 1:57 am

Postby Artur79 » Thu Oct 16, 2008 11:04 am

use AlertDialog class, example here

tinytut_-_displaying_a_messagebox-t54-s15.html
Artur79
Developer
Developer
 
Posts: 26
Joined: Fri Sep 26, 2008 12:53 pm

Postby KanedaSyndrome » Tue Nov 11, 2008 11:46 pm

Hi I have a problem that I hope you can help me with, I will post my code:

Code: Select all
package anritsu.futuretechnologies.connectivity;

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

public class Connectivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
   
        Button backbutton1 = (Button)findViewById(R.id.button_back1);
        Button button1 = (Button)findViewById(R.id.button1);
       
        button1.setOnClickListener(new OnClickListener()
        {
            public void onClick(View viewParam)
            {
               setContentView(R.layout.menupoint1);
            }
       
        });
       
       
        backbutton1.setOnClickListener(new OnClickListener()
        {
            public void onClick(View viewParam)
            {
               setContentView(R.layout.main);
            }
        });
       
                     
    }
}


Now the problem is that I get no errors, but when I try to run it I get an error in the emulator that the activity closed unexpectedly.

This only happens when I try to have two buttons working from the buttonname.setOnClickListener

If I remove one of them and just have one button used it works fine... I don't see what's wrong since I get no errors. Is it because it's under the same oncreate or something? You have it the same way in yours, but perhaps it's because they load a new xml layout file each when they are pushed?

I have main.xml and a menupoint1.xml, the idea is that pressing a button in the main.xml will take the user to the menupoint1.xml layout, and with a back button in menupoint1.xml it should take the user back to main.xml, basically I am just trying to get my head around getting buttons to work.

Or perhaps the error is in the (View viewParam), I am not that sharp with java yet and this might refer to a parameter in the main.xml and when the listener tries to listen on a button that's in a different layout file it messes up?

Anyway, if you could like really cut it out in paper for me, I would be very appreciative.
KanedaSyndrome
Developer
Developer
 
Posts: 41
Joined: Tue Nov 11, 2008 3:32 pm

Thnx

Postby mzaher » Fri Dec 26, 2008 1:03 pm

Thnx plusminus,
Gr8 work. u dont know how happy i am because i was looking for an Android GUI tutorial (XML)
mzaher
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Dec 26, 2008 12:50 pm
Location: Egypt,Cairo

Postby Emistro45 » Mon Apr 13, 2009 3:00 am

You can make an easy GUI with this application, and then generate it into an .XML file.
Get It Here.
Emistro45
Freshman
Freshman
 
Posts: 2
Joined: Sun Apr 12, 2009 9:32 pm

Postby myazuid » Thu Apr 16, 2009 3:43 pm

just to let people know,

A statement is used in this tutorial -

android:layout_toRight="@+id/....."

The command has since been changed to -

android:layout_toRightOf="@+id/......"

Great tut :D
Image
myazuid
Freshman
Freshman
 
Posts: 8
Joined: Fri Feb 27, 2009 6:01 pm
Location: London, England

Postby randheer » Thu Jul 02, 2009 3:25 am

:(
Hi,
I have a problem. Android is not accepting this line.
android:background="@drawable/blue"
It says---> ERROR Error: No resource found that matches the given name (at 'background' with value '@drawable/
blue').

Please tell me the reason why it is so.
randheer
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jun 10, 2009 11:27 am

Postby MatrixPhreak » Sat Jan 02, 2010 3:22 pm

randheer wrote::(
Hi,
I have a problem. Android is not accepting this line.
android:background="@drawable/blue"
It says---> ERROR Error: No resource found that matches the given name (at 'background' with value '@drawable/
blue').

Please tell me the reason why it is so.


Well, do you have a file called "blue" within /res/drawable? For instance, I wanted to use a picture of my girlfriend as the background (just out of curiosity's sake in learning), so I went about it this way:

Right-click within the Package Explorer frame and select "Import" and then "File System" from "General". In the "From Directory" area, either type or browse to the folder that contains your file (in my case, "tootoo.jpg"). In the right pane of the import dialogue, browse and check off the file to import. In the "Into Folder" area, click "Browse" and target /res/drawable. There should be only legal characters in the filename (a-z, A-Z, and 0-9. No funny punctuation or spaces). Click finish and the file should now have been imported into /res/drawable and can now be found with
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. androd:background="@drawable/tootoo"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


However, if you were just trying to make the background blue (as I understand it from your post), the simpler way to do that would be:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:background="#00f"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4
The background value is set as #rgb using standard hex values (which is to say, 0-f). Using this, you can mix to create any color.

Hope this helped out, good luck.
I, for one, welcome our new robotic overlords.
MatrixPhreak
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jan 01, 2010 11:50 pm
Location: CT

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests