Ciao a tutti, scusate il ritardo ma ho fatto il ponte del 25 aprile!!!
Allora, cerco di spiegare quello che ho fatto.
In Eclipse ho creato un nuovo progetto Android e l'ho chiamato come segue:
application name: HelloLinearApp
package: html.it.examples.com
project name: HelloLinear
activity name (che è la public class): HelloLinear
Layout name: main.xml
Poi ho creato altri 2 file:
form.xml (sotto layout)
Form.java (dentro il package)
E ho modificato:
- AndroidManifest.xml
- strings.xml
In fondo a questo messaggio incollo il codice, che è lo stesso che c'è sul sito di html.it.
Eclipse mi segna errori nei file hellolinear.java ed in form.java
Allora in hellolinear alla riga:
codice:
final Button button = (Button) findViewById(R.id.form_button);
mi sottolinea "form_button" (e poco sotto form_button, edit_name, edit_lastname) e cliccando sulla crocetta rossa mi da in una finestra:
codice:
...
public static final class id {
public static final int action_settings=0x7f080000;
public static int form_button;
}
...
Stessa cosa mi è segnalata alle righe:
codice:
case R.id.form_button:
final EditText edit_name = (EditText)findViewById(R.id.edit_name);
final EditText edit_lastname = (EditText)findViewById(R.id.edit_lastname);
Passiamo al file form.java. L'errore l'ho alle seguenti righe:
codice:
setContentView(R.layout.form);
final TextView text_name = (TextView) findViewById(R.id.view_name);
final TextView text_lastname = (TextView) findViewById(R.id.view_lastname);
quello che appare nella solita finestra cliccando sull'errore (form, view_name, view_lastname) è:
codice:
package html.it.examples.com;
import android.view.View;
public final class R {
...
public static final class layout {
public static final int main=0x7f030000;
public static View form;
}
...
Per concludere incollo la descrizione degli errori che mi da eclipse (i problems, come li chiama lui!), sono 7.
codice:
Description Resource Path Location Type
edit_lastname cannot be resolved or is not a field HelloLinear.java /HelloLinear/src/html/it/examples/com line 24 Java Problem
Description Resource Path Location Type
edit_name cannot be resolved or is not a field HelloLinear.java /HelloLinear/src/html/it/examples/com line 23 Java Problem
Description Resource Path Location Type
form cannot be resolved or is not a field Form.java /HelloLinear/src/html/it/examples/com line 10 Java Problem
Description Resource Path Location Type
form_button cannot be resolved or is not a field HelloLinear.java /HelloLinear/src/html/it/examples/com line 15 Java Problem
Description Resource Path Location Type
form_button cannot be resolved or is not a field HelloLinear.java /HelloLinear/src/html/it/examples/com line 22 Java Problem
Description Resource Path Location Type
view_lastname cannot be resolved or is not a field Form.java /HelloLinear/src/html/it/examples/com line 12 Java Problem
Description Resource Path Location Type
view_name cannot be resolved or is not a field Form.java /HelloLinear/src/html/it/examples/com line 11 Java Problem
Grazie in anticipo a tutti!
MAIN
codice:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/label_form_name"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:id="@+id/view_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/label_form_lastname"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:id="@+id/view_lastname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
ELLOLINEAR.JAVA
codice:
package html.it.examples.com;
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 android.widget.EditText;
public class HelloLinear extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.form_button);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch ( v.getId() ) {
case R.id.form_button:
final EditText edit_name = (EditText)findViewById(R.id.edit_name);
final EditText edit_lastname = (EditText)findViewById(R.id.edit_lastname);
Bundle bundle = new Bundle();
bundle.putString("name", edit_name.getText().toString());
bundle.putString("lastname", edit_lastname.getText().toString());
Intent form_intent = new Intent(getApplicationContext(), Form.class);
form_intent.putExtras(bundle);
startActivity(form_intent);
break;
}
}
}
STRINGS.XML
codice:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloLinearApp</string>
<string name="form_intro">Invia il form premendo sul pulsante di invio.</string>
<string name="name">Inserisci il tuo nome</string>
<string name="lastname">Inserisci il tuo cognome</string>
<string name="form_button_label">Invia</string>
<string name="label_form_name">Nome Inserito:</string>
<string name="label_form_lastname">Cognome Inserito:</string>
</resources>
FORM.JAVA
codice:
package html.it.examples.com;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Form extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
final TextView text_name = (TextView) findViewById(R.id.view_name);
final TextView text_lastname = (TextView) findViewById(R.id.view_lastname);
Bundle bundle = this.getIntent().getExtras();
text_name.setText(bundle.getString("name"));
text_lastname.setText(bundle.getString("lastname"));
}
}
public class Form {
}
FORM.XML
codice:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/label_form_name"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:id="@+id/view_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/label_form_lastname"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
/>
<TextView
android:id="@+id/view_lastname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
HELLOLINEAR MANIFEST
codice:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="html.it.examples.com"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HelloLinear"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Form"
android:label="@string/app_name">
<intent-filter/>
</activity>
</application>
</manifest>