Fri*_*ian 0 java eclipse variables android
Eclipse一直告诉我,advancedButton"无法解析或不是一个字段",即使我已经定义它就像我班上的所有其他变量一样.即使我尝试用另一个变量替换它,它也会给我同样的错误.有关为什么会发生这种情况的任何线索?
public void onClick(View w) {
switch(w.getId()){
case R.id.advancedButton:
Intent a = new Intent(Registration.this, RegistrationAdvanced.class);
startActivity(a);
break;
}
Run Code Online (Sandbox Code Playgroud)
整个代码
package com.example.testing;
import java.io.Console;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
public class Registration extends Activity implements OnClickListener{
Button dobButton, countryButton, advancedButton;
ArrayList<String> dobList = new ArrayList<String>();
ArrayList<String> countryList = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
Initialize();
PopulateDate();
PopulateCountries();
}
public void Initialize(){
dobButton = (Button) findViewById(R.id.dob_button);
dobButton.setTag("1");
dobButton.setOnClickListener(this);
countryButton = (Button) findViewById(R.id.country_button);
countryButton.setTag("2");
countryButton.setOnClickListener(this);
advancedButton = (Button) findViewById(R.id.advanced_button);
advancedButton.setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.advancedButton:
Intent a = new Intent(Registration.this, RegistrationAdvanced.class);
startActivity(a);
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
试试这段代码
您的按钮ID R.id.advanced_button已经写好了R.id.advancedButton
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.advanced_button:
Intent a = new Intent(Registration.this, RegistrationAdvanced.class);
startActivity(a);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
viewType_layoutName_ViewName在编写R.id.XXXX时,我遵循命名惯例,所以我不是cofuse
例如,在你的情况下我的按钮ID会 R.id.btn_registration_advance减少混淆ID的机会......
| 归档时间: |
|
| 查看次数: |
111 次 |
| 最近记录: |