2017-01-25 46 views

回答

1

試試這個:

custom_dialog.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.RecyclerView 
    android:id="@+id/my_recycler_view" 
    android:scrollbars="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 
</LinearLayout> 

活動/ Fragment.java

RecyclerView mRecyclerView; 
AlertDialog.Builder builder = new AlertDialog.Builder(context); 
LayoutInflater inflater = LayoutInflater.from(context); 
View content = inflater.inflate(R.layout.custom_dialog, null); 
builder.setView(content); 
mRecyclerView = (RecyclerView) content.findViewById(R.id.my_recycler_view); 
1

你應該擴展DialogFragment並創建將有回收查看自定義對話框在裏面。

佈局: - fragment_dialog.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:scrollbars="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

</RelativeLayout> 

您的自定義對話框: - MyDialogFragment

public class MyDialogFragment extends DialogFragment { 
    private RecyclerView mRecyclerView; 
    // this method create view for your Dialog 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
      //inflate layout with recycler view 
     View v = inflater.inflate(R.layout.fragment_dialog, container, false); 
     mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view); 
     //setadapter 
     //get your recycler view and populate it. 
     return v; 
    } 
}