我已经按照Android网站上的指南创建了一个微调器。我已经完全复制了代码但仍然遇到以下错误:
令牌“setDropDownViewResource”上的语法错误,预期的标识符 在此标记之后
,
令牌“。”上的语法错误,...预期
,
令牌上的语法错误,错位的构造
,
令牌“adapter”上的语法错误,预期后的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);
}}
答案 0 :(得分: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);
}
}
是你的活动代码......