1.這是添加按鈕,當我點擊這裏我應該出現自定義對話框。在android中的自定義對話框?
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);
我沒有得到它,一個幫助了這個錯誤
嘗試使用'dialog.findViewById(...)識別textview',然後在這裏發佈你的logtrace。 – Praveenkumar 2012-07-09 05:34:29
檢查此..:http://stackoverflow.com/a/10652886/1168654 – 2012-07-09 05:49:31