它正在尝试在微调器中添加更多项目,同时在微调器项列表中选择一个选项,使用弹出窗口... 但是在运行时单击“添加”时出现错误(强制关闭)...
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(){
public boolean onTouch(View v,MotionEvent me){
dialog.dismiss();
return false;
}
});
dialog.show();
return;
}
请帮助我...谢谢你的朋友
答案 0 :(得分:0)
我不确定它是否有效但尝试
s1.notifyDataSetChanged();
而不是
s1.setAdapter(adapter);
答案 1 :(得分:0)
回答我的问题:
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();
}
});
非常感谢