我正在创建一个带有项目列表的AlertDialog
。
当前显示的图像:
我想让类别列表项以粗体显示。 有办法做到这一点吗?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Make a choice from the list:");
builder.setCancelable(false);
builder.setItems(R.array.items_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), "Selection: " + item, Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();
最佳答案
即使您只想要标题,我也会使用 ExpandableListView。对于我的一个项目,我遇到了涉及 header 的完全相同的问题,我必须为其创建一个自定义适配器。
首先创建一个新类,其中包含...
public class MyCustomListAdapter extends BaseExpandableListAdapter
这些是我的项目中的“getChildView”和“getGroupView”...
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
DetailInfo detailInfo = (DetailInfo) getChild(groupPosition,
childPosition);
if (view == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.child_row, null);
}
TextView childItem = (TextView) view.findViewById(R.id.childItem);
childItem.setText(detailInfo.getName().trim());
return view;
}
@Override
public View getGroupView(int groupPosition, boolean isLastChild, View view,
ViewGroup parent) {
HeaderInfo headerInfo = (HeaderInfo) getGroup(groupPosition);
if (view == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.group_heading, null);
}
TextView heading = (TextView) view.findViewById(R.id.heading);
heading.setText(headerInfo.getName().trim());
return view;
}
现在,您可以完全控制显示为组或子项的内容。在这种情况下,组显示为标题,子项显示为数据。
这是我的 ListView 使用此代码的屏幕截图......
关于Android 警报对话框列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20927295/