Vogella Tutorial


  1. BranMan

    BranMan New Member

    I'm a C++ and C# programmer and I've been practicing to make android applications to expand my knowledge. Upon downloading eclipse and the android SDK I started off with vogella's basic tutorial for a temperature converter.

    After doing that tutorial I continued onto a menu tutorial where I came upon problems. Here is a link to the tutorial:Android Development Tutorial - Gingerbread

    I'm on #7 and upon creating the preferences.xml file and adding the two attributes it told me to insert code. It doesn't specify where to put this code and I assumed it would be in the HelloPreferences.java file since there are no other available files to add activities to. Then it says to modify the manifest file to make it an actual activity. I did that step but the program still tells me that the Preferences activity needs to be defined in its own file.

    I looked online for solutions to adding a new activity and everyone says either to make a .java file or to add a period in-front of the activity name inside of the manifest file. I tried the period solution and that doesn't solve anything. Is there something in the tutorial that's obvious and I've missed it? I'm so lost and I really want to learn how to make android platform programs. I would greatly appreciate any help.

    Advertisement
  2. alostpacket

    alostpacket Over Macho Grande? VIP Member

    what is your package name?

    can you post code to the manifest also?
  3. BranMan

    BranMan New Member

    I apologize for the long response. The package name is de.vogella.android.preferences.

    Here is the xml for the manifest file:

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="de.vogella.android.preferences"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.     <uses-sdk android:minSdkVersion="8" />
    7.  
    8.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    9.         <activity android:name=".HelloPreferences"
    10.                   android:label="@string/app_name">
    11.             <intent-filter>
    12.                 <action android:name="android.intent.action.MAIN" />
    13.                 <category android:name="android.intent.category.LAUNCHER" />
    14.             </intent-filter>
    15.         </activity>
    16.         <activity android:label="Preferences" android:name="Preferences"></activity>
    17.  
    18.     </application>
    19. </manifest>
  4. alostpacket

    alostpacket Over Macho Grande? VIP Member

    That looks correct assuming the public class
    HelloPreferences

    is in the de/vogella/android/preferences/ folder and has that as it's package name too

    Edit:
    Your second class need a . in front of the name so .Preferences
  5. alostpacket

    alostpacket Over Macho Grande? VIP Member

    also

    <uses-sdk android:minSdkVersion="8" />

    should come after the /application tag and before the /manifest tag
  6. BranMan

    BranMan New Member

    I've done what you have suggested and I'm still getting told that Preferences needs to be defined in its own file. I've seen other people talking about having multiple Activities in a single file but I can't find a clear way to do it. Here is what I have in my HelloPreferences.java file. Maybe I'm missing something.

    Code (Text):
    1. package de.vogella.android.preferences;
    2.  
    3. import android.app.Activity;
    4. import android.os.Bundle;
    5. import android.view.Menu;
    6. import android.view.MenuInflater;
    7. import android.view.MenuItem;
    8. import android.widget.Toast;
    9. import android.preference.PreferenceActivity;
    10.  
    11. //import android.preference.PreferenceActivity;
    12.  
    13. public class HelloPreferences extends Activity
    14. {
    15.     /** Called when the activity is first created. */
    16.     @Override
    17.     public void onCreate(Bundle savedInstanceState)
    18.     {
    19.         super.onCreate(savedInstanceState);
    20.         setContentView(R.layout.main);
    21.     }
    22.    
    23.     @Override
    24.     public boolean onCreateOptionsMenu(Menu menu)
    25.     {
    26.         MenuInflater inflater = getMenuInflater();
    27.         inflater.inflate(R.menu.menu, menu);
    28.         return true;
    29.     }
    30.    
    31.     @Override
    32.     public boolean onOptionsItemSelected(MenuItem item)
    33.     {
    34.         Toast.makeText(this, "Just a test", Toast.LENGTH_SHORT).show();
    35.         return true;
    36.        
    37.     }
    38. }
    39.  
    40. public class Preferences extends PreferenceActivity
    41. {
    42.     /** Called when the activity is first created.*/
    43.     @Override
    44.     public void onCreate(Bundle savedInstanceState)
    45.     {
    46.         super.onCreate(savedInstanceState);
    47.         addPreferencesFromResource(R.xml.preferences);
    48.     }
    49. }
    Adding the period in front of Preferences and moving the sdk version tag didn't seem to do anything but here is what my manifest file is now.

    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    3.       package="de.vogella.android.preferences"
    4.       android:versionCode="1"
    5.       android:versionName="1.0">
    6.    
    7.  
    8.     <application android:icon="@drawable/icon" android:label="@string/app_name">
    9.         <activity android:name=".HelloPreferences"
    10.                   android:label="@string/app_name">
    11.             <intent-filter>
    12.                 <action android:name="android.intent.action.MAIN" />
    13.                 <category android:name="android.intent.category.LAUNCHER" />
    14.             </intent-filter>
    15.         </activity>
    16.         <activity android:label="Preferences" android:name=".Preferences"></activity>
    17.  
    18.     </application>
    19.     <uses-sdk android:minSdkVersion="8" />
    20. </manifest>
    I really do appreciate this help. If you think this tutorial is too complicated for someone new to eclipse or if it's doing something wrong, maybe I should just forget it, but I still want to learn how to handle multiple activities.
Loading...

Share This Page