here is my code:
in it am trying to add more items in the spinner while select one option in the list of spinner items, by the use of popup window... but am getting error(Force close)while click the "add" at run time...
s1 = (Spinner) findViewById(R.id.spinner);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this,android.R.layout.simple_spinner_item,Items);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0,
View arg1, int arg2, long arg3)
{
if(index==2)
{
final Dialog dialog=new Dialog(Starttracker.this);
dialog.setContentView(R.layout.popup);
dialog.setTitle("Enter The Item");
dialog.setCanceledOnTouchOutside(true);
final EditText filename=(EditText)dialog.findViewById(R.id.filename);
filename.setText("");
Button d_ok=(Button)dialog.findViewById(R.id.d_ok);
Button d_cancel=(Button)dialog.findViewById(R.id.d_cancel);
d_ok.setOnTouchListener(new OnTouchListener(){
public boolean onTouch(View v,MotionEvent me){
String textHolder = "" + filename.getText();
adapter.add(textHolder);
s1.setAdapter(adapter);
dialog.dismiss();
return false;
}
});
d_cancel.setOnTouchListener(new OnTouchListener(){
pub开发者_开发百科lic boolean onTouch(View v,MotionEvent me){
dialog.dismiss();
return false;
}
});
dialog.show();
return;
}
pls help me... thanks you friends
I am not sure if it works but try
s1.notifyDataSetChanged();
instead of
s1.setAdapter(adapter);
answer to my question:
d_ok.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
String textHolder = filename.getText().toString();
dialog.dismiss();
Items.add(textHolder);
// s1.setAdapter(adapter);
// notifyDataSetChanged();
}
});
thanks a lot all
精彩评论