我只想在选定的项目微调器上进行alertdialog。这段代码总是出错。
sh = (Spinner) view.findViewById(R.id.shield);
ArrayAdapter<CharSequence> adaptera = ArrayAdapter.createFromResource(getActivity(),
R.array.shield, android.R.layout.simple_spinner_item);
adaptera.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sh.setAdapter(adaptera);
sa = (String) sh.getSelectedItem();
boolean sw = sa.trim().equals("lead");
sw.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
AlertDialog.Builder bu = new AlertDialog.Builder(getActivity());
LayoutInflater d0 = getActivity().getLayoutInflater();
bu.setView(d0.inflate(R.layout.d01, null))
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
return false;
}
});
在alertdialog上使用自定义布局
答案 0 :(得分:0)
您需要使用 OnItemSelectedListener
而不是OnTouchListener
:
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// show alert here
AlertDialog.Builder bu = new AlertDialog.Builder(getActivity());
LayoutInflater d0 = getActivity().getLayoutInflater();
bu.setView(d0.inflate(R.layout.d01, null))
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
.show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
希望它有助于ツ