1.这是添加按钮,当我点击这里时,我应该会出现自定义对话框。
Button add = (Button) findViewById(R.id.addbutton);
// add button listener
add.setOnClickListener(new OnClickListener() {
2.这是自定义对话框代码
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.form);
dialog.setTitle("Custom dailog");
TextView uname_TV = (TextView) findViewById(R.id.Uname_TV);
EditText uname_ET = (EditText) findViewById(R.id.Uname_ET);
TextView dname_TV = (TextView) findViewById(R.id.Drugname_TV);
EditText dname_ET = (EditText) findViewById(R.id.Drugname_ET);
spinner = (Spinner) findViewById(R.id.spinner_id);
ArrayAdapter < String > adapter = new ArrayAdapter < String > (
context, android.R.layout.simple_spinner_item,
noof_times);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setSelection(1);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView <? > parent,
View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
String item1 = parent.getSelectedItem().toString();
Toast.makeText(getApplicationContext(), "Selected:" + item, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView <? > arg0) {
// TODO Auto-generated method stub
}
});
dialog.show();
我正进入(状态
Null pointer exception at spinner.setAdapter(adapter);
我没明白,这个错误的一个帮助