看看我是如何设置我的 Context ctx 的,这就是你要找的。根据使用方式,您可能还需要做一些线程工作。
public class WineSearch extends Activity {
private static String[] names;
private static float[] ratings;
private static int[] ids;
ListView lv;
Context ctx;
TextView searchHeader;
ProgressDialog prgDiag;
Spinner spn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ctx = this;
searchHeader = (TextView) findViewById(R.id.SearchHeader);
lv = (ListView) findViewById(R.id.WineListView);
spn = (Spinner) findViewById(R.id.ListSpin);
ArrayAdapter adapter = ArrayAdapter.createFromResource( this, R.array.list_choice, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spn.setAdapter(adapter);
spn.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long arg3) {
Toast.makeText(parent.getContext(), parent.getItemAtPosition(position).toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
prgDiag = new ProgressDialog(this);
prgDiag.setCancelable(false);
this.refreshList();
}