首页 > 解决方案 > 我在助手应用程序上编程 java 时遇到问题

问题描述

该应用程序应该从另一个屏幕调用一个屏幕并使用另一个屏幕的布局组件。每当我尝试调用一个组件时,例如ImageButton,它说成员 ID 未知,我告诉我的老师,他说这不应该发生。我尝试重命名组件,甚至创建了一个新项目。

我该如何解决?错误在 R.id 中

package com.movil.ejemploventanas;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;

public class DatosPersonales extends Activity {
EditText vEdtNom,vEdtEdad;
ImageButton vBtnOrigen,vBtnSantuario;
Intent intnEnvio;
Bundle bndContenedorEnvio;
String strNom;
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.datospersonales);
    vEdtNom=(EditText)findViewById(R.id.edtNom);
    vEdtEdad=(EditText)findViewById(R.id.edtEdad);
    vBtnOrigen=(ImageButton)findViewById(R.id.btnOrigen);
    vBtnSantuario=(ImageButton)findViewById(R.id.btnSantuario);
    intnEnvio=new Intent(DatosPersonales.this,Caracteristicas.class);
    bndContenedorEnvio=new Bundle();
    vBtnOrigen.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0){
                strNom=vEdtNom.getText().toString();
                bndContenedorEnvio.putString("nom",strNom);
                bndContenedorEnvio.putString("edad", vEdtEdad.getText().toString());
                bndContenedorEnvio.putString("opc","1");
                intnEnvio.putExtras(bndContenedorEnvio);
                startActivity(intnEnvio);
            }
        });
    vBtnSantuario.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0){
                strNom=vEdtNom.getText().toString();
                bndContenedorEnvio.putString("nom",strNom);
                bndContenedorEnvio.putString("edad",vEdtEdad.getText().toString());
                bndContenedorEnvio.putString("opc","2");
                intnEnvio.putExtras(bndContenedorEnvio);
                startActivity(intnEnvio);
            }
        });
}

}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:id="@+id/txtLetrero"
    style="style/titulo"
    android:layout_centerHorizontal="true"
    android:text="@string/letMariposa"/>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/txtLetrero"
    android:id="@+id/linearlayout1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="66dp">

    <TextView
        android:id="@+id/txtNom"
        style="style/letreros"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text="string/nom"/>

    <EditText
        android:id="@+id/edtNom"
        style="style/datos"
        android:layout_width="220dp"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"/>

</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/linearLayout1"
    android:id="@+id/linearlayout2"
    android:layout_centerHorizontal="true">

    <TextView
        android:id="@+id/txtEdad"
        style="style/letreros"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:text="@string/edad"
        android:textAlignment="gravity"/>

    <EditText
        android:id="@+id/edtEdad"
        style="style/datos"
        android:layout_width="220dp"
        android:ems="10"
        android:layout_height="wrap_content"
        android:inputType="number"/>

</LinearLayout>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/origen"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_below="@+id/linearLayout2"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="200dp"
    android:id="@+id/textView4"
    style="style/letreros"/>

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_below="@id/textView4"
    android:layout_marginLeft="80dp"
    android:id="@+id/btnOrigen"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sant"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:layout_below="@+id/btnOrigen"
    android:layout_marginLeft="120dp"
    android:id="@+id/textView5"
    style="style/letreros"/>

<ImageButton
    android:id="@+id/btnSantuario"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView5"
    android:layout_marginLeft="180dp"/>

</RelativeLayout>

标签: java

解决方案


推荐阅读