-1

我已经按照 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);

}}  
4

1 回答 1

1

你有没有像这个例子那样做

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);
}
}

你的活动代码是这样的吗……

于 2013-02-15T18:15:34.257 回答