好吧基本上我有自定义 ListView 和 onClick 的列表项(按钮)我想打开一个对话框,它应该基本上显示另一个ListView。我可以查看两个列表,但问题是我的对话框列表视图没有在对话框中显示列表。它只是一个透明的列表在上一个列表的顶部。但是如果尝试设置Dialog Title getDialog().setTitle("Apps List");
我会得到上面提到的错误,这意味着我在第一个地方没有对话但是为什么?。
public class ProfileDialog extends android.support.v4.app.DialogFragment {
.........
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ArrayList<String> listItemTitle = new ArrayList<String>();
listItemTitle.add("Hello");
listItemTitle.add("Hello1");
listItemTitle.add("Hello2");
listItemTitle.add("Hello3");
ArrayList<String> listItemType = new ArrayList<String>();
listItemType.add("Hello");
listItemType.add("Hello123");
listItemType.add("1234");
listItemType.add("Hello6666");
ArrayList<Integer> listItemId = new ArrayList<Integer>();
listItemId.add(1);
listItemId.add(2);
listItemId.add(3);
listItemId.add(4);
ArrayList<Profile> ProfileArrayList = new ArrayList<>();
for (int i = 0; i < listItemTitle.size(); i++) {
Profile Profile = new Profile(listItemTitle.get(i), listItemType.get(i), listItemId.get(i));
ProfileArrayList.add(Profile);
}
View profileView = inflater.inflate(R.layout.fragment_profile_dialog, container, false);
ListView profileListView = (ListView) profileView.findViewById(R.id.lstvSelectedProfile);
getDialog().setTitle("Apps List");
// ListView profileListView = (ListView) LayoutInflater.from(context).inflate(R.layout.fragment_profile_dialog, null);
if(profileListView.getParent()!=null) {
((ViewGroup) profileListView.getParent()).removeView(profileListView);
}
SelectedProfileListAdapter adapter = new SelectedProfileListAdapter(getActivity().getApplicationContext(), ProfileArrayList);
profileListView.setAdapter(adapter);
return profileListView;
}
这是我的Adapater填充了第二个列表。
public class SelectedProfileListAdapter extends BaseAdapter{
private LayoutInflater layoutInflater;
private List<Profile> selectedProfileList;
public SelectedProfileListAdapter(Context context, List<Profile> selectedProfileList) {
layoutInflater =(LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
this.selectedProfileList = selectedProfileList;
// this.context = context;
}
...........
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ProfilesListAdapter.ViewHolder ProfileListViewHolder;
if (convertView == null) {
ProfileListViewHolder = new ProfilesListAdapter.ViewHolder();
convertView = layoutInflater.inflate(R.layout.adapter_profiles_list, parent, false);
ProfileListViewHolder.title = (TextView) convertView.findViewById(R.id.title);
ProfileListViewHolder.textView3 = (TextView) convertView.findViewById(R.id.textView3);
ProfileListViewHolder.imageButtonMore = (ImageButton) convertView.findViewById(R.id.imgButtonMore);
convertView.setTag(ProfileListViewHolder);
} else {
ProfileListViewHolder = (ProfilesListAdapter.ViewHolder) convertView.getTag();
}
ProfileListViewHolder.textView3.setText(selectedProfileList.get(position).getTitle());
ProfileListViewHolder.title.setText(selectedProfileList.get(position).getType());
ProfileListViewHolder.imageButtonMore = (ImageButton) convertView.findViewById(R.id.imgButtonMore);
ProfileListViewHolder.imageButtonMore.setTag(selectedProfileList.get(position).getId());
return convertView;
}
}
答案 0 :(得分:0)
您可以覆盖onCreateDialog()
方法并在那里添加标题......
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setTitle("Apps List");
return dialog;
}
修改强>
res / styles.xml中的:添加自定义对话框样式
<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
现在使用:在您的父片段
中应用它ProfileDialog fragment = new ProfileDialog();
fragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog);