我是 Android 新手,正在尝试导航和显示信息。我成功地在这个应用程序的主视图上放置了一个微调器,但是当我单击另一个视图(通过执行 goFilter 的按钮)并返回(通过执行 goHome 的按钮)时,会出现一个占位符。我确定这与 goHome 未加载微调器类信息有关,但我不知道如何以不同的方式进行操作。
建议?.java 代码如下:
package com.example.hellorelative;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
public class HelloRelative extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(), "The planet is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
public void goFilter(View view) {
setContentView(R.layout.c_filter);
}
public void goHome(View view) {
setContentView(R.layout.main);
}
}