我在我的GridView中有一個問題,我在我的警報箱中插入了我的GridView,但是我的setOnitemClicklistener的函數不在我的警報箱中工作。如何在gridview的alertbox中實現setOnitemClicklistener。任何建議對這個問題Android Gridview setOnitemClicklisterner在警報對話框中沒有功能
LayoutInflater li = LayoutInflater.from(getActivity());
View promptsView = li.inflate(R.layout.prompt_quantity, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
// set prompts.xml to alertdialog builder
alertDialogBuilder.setView(promptsView);
final GridView modifiergridview = (GridView) promptsView.findViewById(R.id.modifiergridview);
modifierList = db.getModifierName(pName);
modifiergridview.setAdapter(new Modifierlist());
modifiergridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "test", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
alertDialog.getWindow().setLayout(2000, 2000);
}
});
Modifierlist.java
public class Modifierlist extends BaseAdapter {
LayoutInflater mInflater;
private ArrayList<Integer> positions = new ArrayList<Integer>();
public ArrayList<Integer> getPositions() {
return positions;
}
public Modifierlist() {
mInflater = LayoutInflater.from(getActivity());
}
@Override
public int getCount() {
return modifierList.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.modifierlistview, null);
}
modifiername = (Button) convertView.findViewById(R.id.modifierbutton);
Modifier myObj = modifierList.get(position);
modifiername.setText("" + myObj.getModifierName());
return convertView;
}
}
,請複製粘貼Modifierlist()類代碼? –