0

好了,所以基本上我有列表項(按鈕)我想打開一個對話框,這應該基本上表現出另一種的ListView的定製的ListView的onClick。我可以查看這兩個列表就好了,但問題是我的對話框列表視圖不顯示對話框中的列表。它只是一個透明的列表頂部上一個列表。但是,如果嘗試設置對話框標題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; 
    } 

} 
+1

我認爲你已經在DialogFragment onCreateView()中返回了錯誤的視圖。你重新建立了「profileListView」,它只是列表。嘗試將其更改爲「profileView」。希望有所幫助! –

回答

0

可以覆蓋onCreateDialog()方法並添加您的標題有...

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    Dialog dialog = super.onCreateDialog(savedInstanceState); 
    dialog.setTitle("Apps List"); 
    return dialog; 
} 

編輯在資源

/styles.xml:添加自定義的對話風格

<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog"> 
    <item name="android:windowNoTitle">false</item> 
</style> 

現在將其應用於:在您的父級碎片ent

ProfileDialog fragment = new ProfileDialog(); 
fragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog); 
+0

沒有影響。它仍然相同 –

+0

我編輯了答案... – rafsanahmad007

+0

感謝您的答案隊友,它有點幫助我,但問題是,我的對話框看起來不像一個對話框,其載入對話框,但其背景是透明的。所以我不確定,這裏有什麼問題。 –