Android开发的微调器

Android开发的微调器,android,Android,我按照android网站上的指南创建了一个微调器。我已经完全复制了代码,但仍然出现以下错误: 令牌“setDropDownViewResource”上的语法错误,应为标识符 在此令牌之后 , 令牌“”上的语法错误。。。期望 , 令牌上的语法错误,构造位置错误 , 令牌“适配器”上的语法错误,应在之后使用VariableDeclaratorId 这个令牌 如果有人能帮我解决这些问题,我将不胜感激 我已经在下面显示了代码 package com.example.myfirstapp; i

我按照android网站上的指南创建了一个微调器。我已经完全复制了代码,但仍然出现以下错误:

令牌“setDropDownViewResource”上的语法错误,应为标识符 在此令牌之后

,

令牌“”上的语法错误。。。期望

,

令牌上的语法错误,构造位置错误

,

令牌“适配器”上的语法错误,应在之后使用VariableDeclaratorId 这个令牌

如果有人能帮我解决这些问题,我将不胜感激

我已经在下面显示了代码

     package com.example.myfirstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;



public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
    public final static String EXTRA_MESSAGE_COLOR = "com.example.myfirstapp.MESSAGE2";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }  


    Spinner spinner = (Spinner) findViewById(R.id.spinner);
 // Create an ArrayAdapter using the string array and a default spinner layout
 ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
         R.array.color_array, android.R.layout.simple_spinner_item);
 // Specify the layout to use when the list of choices appears
 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 // Apply the adapter to the spinner
 spinner.setAdapter(adapter);


/** Called when the user clicks the Send button */
public void sendMessage (View view)   {
    Intent i = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.edit_message);
    //EditText editTextcolor = (EditText) findViewById(R.id.edit_message_color);
    String message = editText.getText().toString();
    //String messagecolor = editTextcolor.getText().toString();
    Bundle extras = new Bundle();
    extras.putString(EXTRA_MESSAGE, message);
    //extras.putString(EXTRA_MESSAGE_COLOR, messagecolor );
    i.putExtras(extras);
    startActivity(i);

}}  
package com.example.myfirstapp;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.Menu;
导入android.view.view;
导入android.widget.ArrayAdapter;
导入android.widget.EditText;
导入android.widget.Spinner;
公共类MainActivity扩展了活动{
公共最终静态字符串EXTRA_MESSAGE=“com.example.myfirstapp.MESSAGE”;
公共最终静态字符串EXTRA_MESSAGE_COLOR=“com.example.myfirstapp.MESSAGE2”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.activity\u主菜单);
返回true;
}  
微调器微调器=(微调器)findViewById(R.id.Spinner);
//使用字符串数组和默认微调器布局创建ArrayAdapter
ArrayAdapter=ArrayAdapter.createFromResource(此,
R.array.color\u数组,android.R.layout.simple\u微调器\u项);
//指定显示选项列表时要使用的布局
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
//将适配器应用于微调器
旋转器。设置适配器(适配器);
/**当用户单击“发送”按钮时调用*/
公共无效发送消息(查看){
Intent i=新的Intent(这个,DisplayMessageActivity.class);
EditText EditText=(EditText)findViewById(R.id.edit_消息);
//EditText editTextcolor=(EditText)findViewById(R.id.edit\u message\u color);
String message=editText.getText().toString();
//字符串messagecolor=editTextcolor.getText().toString();
Bundle extras=新Bundle();
额外的putString(额外的消息,消息);
//extras.putString(EXTRA_MESSAGE_COLOR,messagecolor);
i、 临时演员(临时演员);
星触觉(i);
}}  

您是否像这样做过

public class MySpinner extends Activity {
public void onCreate(Bundle b){

// make sure that you have set the content view
setContentView(R.id.layout);
Spinner spinner = (Spinner) findViewById(R.id.building);

// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.buildings_array, android.R.layout.simple_spinner_item);

// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

// Apply the adapter to the spinner
spinner.setAdapter(adapter);
super.onCreate(b);
}
}
公共类MySpinner扩展活动{
创建时的公共void(Bundle b){
//确保已设置内容视图
setContentView(R.id.layout);
微调器微调器=(微调器)findViewById(R.id.building);
//使用字符串数组和默认微调器布局创建ArrayAdapter
ArrayAdapter=ArrayAdapter.createFromResource(此,
R.array.buildings\u array,android.R.layout.simple\u微调器\u项);
//指定显示选项列表时要使用的布局
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
//将适配器应用于微调器
旋转器。设置适配器(适配器);
super.onCreate(b);
}
}

您的活动代码是这样的吗?

按ctrl+shift+o一次……我尝试了这个方法,但我认为它不起作用,因为我在这个活动中引用了其他布局文件。如果我添加import android.R这个R.id。在活动的其余部分中,是否不使用其他布局文件。。?你这是什么意思……你的代码就像我在后期编辑的代码一样,还有很多其他的东西在进行。我会把整个代码放进去。