Sudoku Problem(Hello Android-Book)

Put your problem here if it does not fit any of the other categories.

Sudoku Problem(Hello Android-Book)

Postby nin2246 » Fri Jan 20, 2012 7:43 pm

I am a beginner Android programmer and I am working on the book Hello Android (Google search Hello Android.pdf first link for a online version free) and the first coding application is a sudoku game. Well I am at the part where we make the buttons and title in the middle of the screen and changing background color but I having a problem...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/backgroundX" // Made backgroundX because background was not being found //
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="30dip"
android:orientation="horizontal" >
<LinearLayout // Is being told this is useless removing this means duplicate layout_width/ height //
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center" >

I tried removing LinearLayout for to work and it will launch after I remove the duplicate hieght/ width but it makes the buttons off the screen and onlyh half the screen has background color... Their is no errors other then LinearLayout no java has been added yet. all strings are okay. I also added a new .xml called "color.xml" why? It told me to so I can organize strings and colors.
nin2246
Developer
Developer
 
Posts: 42
Joined: Wed Jan 18, 2012 8:08 pm

Top

Re: Sudoku Problem(Hello Android-Book)

Postby Phyll » Fri Jan 20, 2012 8:12 pm

Hi nin,

I'm not familiar with the book you reference but if you are asking about the two linearlayouts, they are probably nested. I say probably because you are only showing part of the layout. They probably have the buttons above or below the text. The horizontal linearlayout positions the two buttons and the vertical layout positions the text in relation to the buttons group. It kind of looks backwards in your post.

The height and width in each layout governs its individual use of its own space.

If you want better answer, please show us whole code and errors from logcat if possible.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Sudoku Problem(Hello Android-Book)

Postby nin2246 » Fri Jan 20, 2012 8:26 pm

This is what the book says I need copied straight from the .pdf version --
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/background"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="30dip"
android:orientation="horizontal" >
<LinearLayout // This is what is bugging and messing up saying it is useless and not needed. I delete it then layout_hieght width will duplicate and bug up thus delete those to make it "run" //
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center" >
<TextView
android:text="@string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp" />
<Button
android:id="@+id/continue_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_label" />
<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/new_game_label" />
<Button
android:id="@+id/about_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/about_label" />
<Button
android:id="@+id/exit_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/exit_label" />
</LinearLayout>
</LinearLayout>


This is what I have to make it work where it displays all the buttons I fixed it a tad bit still doesn't look 100% like it should. I got rid of the 2nd <LinearLayout so the background color will only fill part of the screen. Not all of it as I am trying.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/backgroundX"
android:layout_width="fill_parent"
android:padding="30dip"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_gravity="center" >
    <TextView
        android:text="@string/main_title"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_gravity="center"
      android:layout_marginBottom="150dip"
      android:textSize="24.5sp" />

    <Button
        android:id="@+id/continue_button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/continue_label" />
    <Button
        android:id="@+id/new_button"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/new_game_label" />
    <Button
        android:id="@+id/about_button"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/about_label" />
    <Button
        android:id="@+id/exit_button"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@string/exit_label" />
      
</LinearLayout>


Log Cat (I don't know how to copy it, I guess I did it right, never really looked at it before as I don't know what it all means...)

Code: Select all
01-20 13:12:17.147: D/InputEventConsistencyVerifier(735):   2: sent at 4408756000000, (unhandled) KeyEvent { action=ACTION_UP, keyCode=KEYCODE_DPAD_LEFT, scanCode=103, metaState=0, flags=0x80000008, repeatCount=0, eventTime=4408756, downTime=4408691, deviceId=0, source=0x301 }


Strings.xml code
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Sudoku</string>
    <string name="main_title">Android Sudoku</string>
    <string name="continue_label">Continue</string>
    <string name="new_game_label">New Game</string>
    <string name="about_label">About</string>
    <string name="exit_label">Exit</string>
    <string name="background">#3500ffff</string>
   
</resources>


colors.xml code (Only one color being changed)
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="backgroundX">#3500ffff</color>
</resources>


sudoku.java code (I have done nothing to it, I don't think the book said anything about this yet coding wise.)

Code: Select all
package org.example.sudoku;

import android.app.Activity;
import android.os.Bundle;

public class sudoku extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
   }
}
nin2246
Developer
Developer
 
Posts: 42
Joined: Wed Jan 18, 2012 8:08 pm

Re: Sudoku Problem(Hello Android-Book)

Postby Phyll » Fri Jan 20, 2012 9:08 pm

Hi nin,

That worked fine as far as I can tell. Should it look like this?

Image

Find the project for v2.1 attached.

Hope this helps.

Phyll
Attachments
Sudoku.zip
Sudoku Example
(34.06 KiB) Downloaded 40 times
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: Sudoku Problem(Hello Android-Book)

Postby nin2246 » Mon Jan 23, 2012 6:38 pm

Phyll wrote:Hi nin,

That worked fine as far as I can tell. Should it look like this?

Sorry it took long for me to respond my internet was down for the weekand.
I found out what I had missing, and it works now. Now I just gotta finish the rest of it. Thanks a lot for the help Phyll
nin2246
Developer
Developer
 
Posts: 42
Joined: Wed Jan 18, 2012 8:08 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 11 guests