Help Needed

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Help Needed

Postby sm » Sat Sep 13, 2008 8:02 pm

Pls help me with the problems:


This is my mainactivity source code



The errors I get are marked in bold



//package org.anddev.android.subactivitywithresult;
package com.android.mainactivity;
import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

//import com.android.R;

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




public class Mainactivity extends Activity {
protected static final int SUB_ACTIVITY_REQUEST_CODE = 1337;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Apply our main.xml-Layout
setContentView(R.layout.main); //1) R.layout.main cannot be resolve

// Find the button defined in the main.xml
Button cmd_opensub = (Button)findViewById(R.id.mainactivity_cmd_opensub); // R.id.mainactivity_cmd_opensub cannot be resolved
// Add an OnClickListener to it, that will open the SubActivity
cmd_opensub.setOnClickListener(new OnClickListener(){
// @Override
public void onClick(View arg0) {
Intent i = new Intent(MainActivity.this, // Main activity cannot be resolved to a type
SubActivityWithResult.class);
// We use SUB_ACTIVITY_REQUEST_CODE as an 'identifier'
startSubActivity(i, SUB_ACTIVITY_REQUEST_CODE);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
String data, Bundle extras) {
super.onActivityResult(requestCode, resultCode, data, extras);
// Here We identify the subActivity we starte
if(requestCode == SUB_ACTIVITY_REQUEST_CODE){
// And show its result
showAlert("SubActivity returned", "ReturnValue: " + data,
"OK", false);
}
}
}

An error on showAlert, onActivityResult as well is shown




The subactivitywithresult code is:

//package org.anddev.android.subactivitywithresult;
package com.android.subactivitywithresult;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class SubActivityWithResult extends Activity{

protected final int SUCCESS_RETURN_CODE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Apply our subactivity.xml-Layout
setContentView(R.layout.subactivity);

// Find the button defined in the subactivity.xml
Button cmd_return = (Button)findViewById(R.id.subactivity_cmd_return);
/* Add an OnClickListener to it, that will
* read out the text in the EditBox set it
* as retrn-data and close this activity */
cmd_return.setOnClickListener(new OnClickListener(){
// @Override
public void onClick(View arg0) {
// Find the edittext defined in the subactivity.xml
EditText edit_returvalue = (EditText)findViewById(
R.id.subactivity_edit_returnvalue);
SubActivityWithResult.this.setResult(SUCCESS_RETURN_CODE,
edit_returvalue.getText().toString());
// Close this Activity
SubActivityWithResult.this.finish();
}
});
}
}



The AndroidManifest.xml code is: Also gives errors


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.anddev.android.subactivitywithresult">
<application android:icon="@drawable/icon">
<activity class=".MainActivity" android:label="@string/main_app_name">
<intent-filter>
<action android:value="android.intent.action.MAIN" />
<category android:value="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity class=".SubActivityWithResult" android:label="@string/sub_app_name">
<intent-filter>
<action android:value="android.intent.action.VIEW" />
<category android:value="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

pls help with all these errors:

Anyone worked on SDK 0.9 with this code, pls post the working code.


Thanks a lot!
sm
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Sep 05, 2008 2:54 am

Top

Postby plusminus » Sun Sep 14, 2008 12:14 am

Maybe have a look here:

viewtopic.php?p=10158#10158
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

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests