1

这是我的课

package com.example.payrollapplication.details;


import com.example.payrollapplication.R;

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 AddEmployee extends Activity implements OnClickListener{

EditText e_name, e_designation, e_phone, e_age, e_basic, e_ot, e_pf, e_otheralloances;

Button b_save, b_cancel , b_reset;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.employee_entry);


    e_name = (EditText)findViewById(R.id.enameedit);
    e_designation = (EditText)findViewById(R.id.edesignationedit);
    e_phone = (EditText)findViewById(R.id.enumberedit);
    e_age = (EditText)findViewById(R.id.eageedit);
    e_basic = (EditText)findViewById(R.id.ebasicpayedit);
    e_ot = (EditText)findViewById(R.id.eovertimeedit);
    e_pf = (EditText)findViewById(R.id.epfedit);
    e_otheralloances = (EditText)findViewById(R.id.eotheralloanceedit);


    b_save=(Button)findViewById(R.id.savebutton);
    b_cancel=(Button)findViewById(R.id.cancelbutton);
    b_reset=(Button)findViewById(R.id.resetbutton);


    b_save.setOnClickListener(this);    
    b_cancel.setOnClickListener(this);
    b_reset.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()) {

    case R.id.b_save:


        break;

    case R.id.b_cancel:


        break;

    case R.id.b_reset:


        break;



    }
}

}

这是我的 XML

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/background"
android:gravity="top" >



<TextView
    android:id="@+id/TV"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginTop="20sp"
    android:gravity="center_horizontal"
    android:text="Employee Entry details"
    android:textColor="#000000"
    android:textSize="35sp"
    android:textStyle="italic" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="750sp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/TV"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50sp">

        <TextView
            android:id="@+id/enametext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee Name:"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp" />

        <EditText
            android:id="@+id/enameedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/edesignationtext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee Designation:"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/edesignationedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/enumbertext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee Phone Number:"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/enumberedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10" >

            <requestFocus />
        </EditText>

    </TableRow>

    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/eagetext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee Age :"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/eageedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/ebasicpaytext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee Basic Pay :"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/ebasicpayedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/eovertimetext"
            android:layout_width="250sp"
            android:layout_height="wrap_content"
            android:text="Employee over time :"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/eovertimeedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/epftext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee PF deduction :"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/epfedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>


    <TableRow
        android:id="@+id/tableRow6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20sp">

        <TextView
            android:id="@+id/eotheralloancetext"
            android:layout_width="260sp"
            android:layout_height="wrap_content"
            android:text="Employee Other alloances :"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000"
            android:textSize="30sp"/>

        <EditText
            android:id="@+id/eotheralloanceedit"
            android:layout_width="350sp"
            android:layout_height="wrap_content"
            android:ems="10"/>
    </TableRow>
</LinearLayout>


<TableRow
    android:id="@+id/tableRow7"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="24dp" >

    <Button
        android:id="@+id/savebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="60sp"
        android:background="#ffffff"
        android:text="Save"
        android:textColor="#000000"
        android:textSize="30sp" />

    <Button
        android:id="@+id/cancelbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="130sp"
        android:background="#ffffff"
        android:text="Cancel"
        android:textColor="#000000"
        android:textSize="30sp" />

    <Button
        android:id="@+id/resetbutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110sp"
        android:background="#ffffff"
        android:text="Reset"
        android:textColor="#000000"
        android:textSize="30sp" />
</TableRow>

现在在 case R.Id.b_save: 和 caseR.id.b_cancel和 case的 on Click 函数中R.id.b_reset,它给出了错误"Cannot be resolved or is not a field"。我已经清理了项目并重新启动它,我正在使用 Eclipse,这与我在与同一项目相关的另一个类中使文本视图可单击时遇到的错误相同,可能的解决方案是什么?我已经尽我所能,我可以在我的目录中看到 R.Java 文件

谢谢!

4

2 回答 2

1

你有用

case R.id.b_save:


        break;

    case R.id.b_cancel:


        break;

    case R.id.b_reset:

你应该使用

case R.id.savebutton:


        break;

    case R.id.cancelbutton:


        break;

    case R.id.resetbutton:

:) 希望你明白

于 2013-07-24T07:31:31.070 回答
1

这是答案:

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()) {

    case R.id.savebutton:


        break;

    case R.id.cancelbutton:


        break;

    case R.id.resetbutton:


        break;



    }
}
于 2013-07-24T07:31:35.447 回答