Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/06/2012, 19:21
reethok
 
Fecha de Ingreso: abril-2011
Mensajes: 224
Antigüedad: 13 años
Puntos: 8
Pregunta Problema básico en android (tiene que ver don id's)

Bueno, estoy empezando con Android (ya sé algo de Java) y me ha surgido con un problema bastante básico! (estoy siguiendo un videotutorial).

Verán, les muestro el código:

Código Main.xml:
Ver original
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent"
  5.     android:orientation="vertical" >
  6.  
  7.     <TextView
  8.         android:layout_width="wrap_content"
  9.         android:layout_height="wrap_content"
  10.         android:text="Tu total es 0"
  11.         android:textSize="45dp"
  12.         android:layout_gravity="center"
  13.         android:id="@+id/tvDisplay" /> // Problema?
  14.    
  15.     <Button
  16.         android:layout_width="250dp"
  17.         android:layout_height="wrap_content"
  18.         android:text="+1"
  19.         android:textSize="20dp"
  20.         android:layout_gravity="center"
  21.         android:id="@+id/bSumar" /> // Problema ?
  22.    
  23.     <Button
  24.         android:layout_width="250dp"
  25.         android:layout_height="wrap_content"
  26.         android:text="-1"
  27.         android:textSize="20dp"
  28.         android:layout_gravity="center"
  29.         android:id="@+id/bRestar" /> // Priblema ?
  30.  
  31. </LinearLayout>

Bueno aquí asigno id's, pero al parecer no se guardan o no sé (aún no entiendo bien Android).

Y en la clase de la activity principal pasa esto:

Código PruebasImoxActiviry.java:
Ver original
  1. package com.imoxgames.primerjuego;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.widget.Button;
  6. import android.widget.TextView;
  7.  
  8. public class PruebasImoxActivity extends Activity {
  9.     /** Called when the activity is first created. */
  10.    
  11.     int contador;
  12.     Button sumar;
  13.     Button restar;
  14.     TextView display;
  15.    
  16.     @Override
  17.     public void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.main);
  20.        
  21.         contador = 0;
  22.         sumar = (Button) findViewById(R.id.bSumar); // ERROR
  23.        
  24.     }
  25. }

En esa linea (donde marqué error) me sale: id cannot be resolver or is not a field.

¿A qué se debe esto?
¿Qué hago?

Muchísimas gracias por su ayuda!