December 17, 2012

What am i doing wrong in this SlidingDrawer android Java SE coding?

Q. Ok, so im sort of a beginner when it comes to this. I bought a book, Android Apps for Absolute Beginners by Wallace Jackson, and have been learning about how to code Android apps. I am using Eclipse IDE. I'm stuck on the SlidingDrawer part of a chapter. heres my appilcation code:
package my.fitness.app;

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

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

heres my strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, myfitnessappActivity!</string>
<string name="app_name">myfitnessapp</string>
</resources>

heres my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<SlidingDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer"
android:layout_width="320dip"
android:layout_height="440dip"
android:orientation="vertical"
android:handle="@+id/handle"
android:content="@+id/content">

<ImageView
android:id="@+id/handle"
android:layout_width="48dip"
android:layout_height="30dip"
android:src="/res/photos/falcon_1920_1200-1680x1050"/>

<AnalogClock
android:id="@+id/content"
android:background="#FFFFFF"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

</SlidingDrawer>
</RelativeLayout>

I've had the most trouble from adding a photo to this code. I've tried the whole "@photos/falcon_1920_1200-1680x1050"/> thing but it doesnt seem to work. Everytime I try to run this in my android emulator, it says there are errors and i must fix them before running the application. what am i doing wrong? thanks in advance!!! :)

A. try here http://code.google.com/p/android/issues/detail?id=3162


Help I'm trying to make a simple android program but the main.xml class has an error?
Q. This is my code, the target build is 2.2 (froyo) this is the main.xml file


<?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/phone_icon�
android:layout_width=�wrap_content�
android:layout_height=�wrap_content�
android:layout_gravity=�center_horizontal�
android:src=�@drawable/phone_on�
/>

<Button
android:id=�@+id/toggleButton�
android:layout_width=�wrap_content�
android:layout_height=�wrap_content�
android:layout_gravity=�center_horizontal�
android:text=�Toggle Silent Mode�
/>

</LinearLayout>

A. Report this problem to the programming service to get things fixed.


Why isn't my Android program working?
Q. I am new to programming for the Android and am trying to write a relatively simple math program. I tried running the program in an emulator, but it hits an error upon start up. This happened after I added 2 other activities. I also changed the first activity in the manifest file (I decided I wanted a different activity to appear first). Could the problem lie in the manifest file, or is there some confusion with the spinner and the startActiviy? I have absolutely no idea what is wrong. Perhaps someone could walk me through using Eclipse's debugger or tell me what my error is (if its simple to see).

Here is the manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.math.mathapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".MainActivity.Main"> //This is what I changed
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Formulas"></activity>
<activity android:name=".Parabola"></activity>

</application>
</manifest>

Here is the Main.java:

public class Main extends Activity {
/** Called when the activity is first created. */

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

Spinner spinner1 = (Spinner) findViewById(R.id.spinnermain);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.program_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter);

spinner1.setOnItemSelectedListener(new programspinner());
}

public class programspinner implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Intent intent = null;
String program;
program = parent.getItemAtPosition(pos).toString();
if(program=="Formula")
intent = new Intent(view.getContext(), Formulas.class);
if(program=="Parabola")
intent = new Intent(view.getContext(), Parabola.class);
startActivity(intent);
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
}


And here is 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"
android:background="@drawable/blackbackground"
android:padding="10dip"
>
<ImageView android:src="@drawable/title"
android:layout_width="wrap_content"
android:id="@+id/imageView1"
android:layout_height="wrap_content"
android:layout_gravity="top"></ImageView>

<Spinner android:layout_width="match_parent"
android:id="@+id/spinnermain"
android:layout_height="wrap_content"
></Spinner>
</LinearLayout>

A.





Powered by Yahoo! Answers

No comments:

Post a Comment