2016-03-05 12 views
9

AppCompat destek kütüphanesinin v23.2 sürümü ile birlikte, BottomSheetDialogFragment'i kullanmaya karar verdim. Bir liste görünümünde bir öğeyi tıklattığımda (bağdaştırıcıya bağladım, böylece bir imleci temsil ediyor) alt sayfayı açmaya çalışıyorum. Tıklandığında, imlecin kimliğini DialogFragment öğesine geçiririm ve içerik sağlayıcının alt sayfayı doldurmasını isteme.BottomSheetDialogFragment - İçeriği nasıl sarmak ve tamamen görüntülemek için?

Her şey yolunda gibi görünüyor, sorun şu ki alt sayfa açıldığında, sadece en üstteki TextView'i görüyorum, ancak alt sayfaya iletilen tüm düzeni görüntülemek istiyorum. İşte

şimdi ne var:

alt tabaka iletişim kutusunu açmak için ListView içeren parçası, içinde

1):

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      int clickedPersonId = ((Cursor) mListView.getItemAtPosition(position)).getInt(FriendsFragment.COL_PERSONS_ID); 
      Log.v("FriendsFragment", "Clicked person with personid = " + clickedPersonId); 

      PersonBottomSheetFragment personBSDF = PersonBottomSheetFragment.newInstance(clickedPersonId); 
      personBSDF.show(getFragmentManager(), "BOTTOM_SHEET_PERSON"); 
     } 
    }); 

2) fragment_person_bottom_sheet.xml

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

<TextView 
    android:id="@+id/fragment_person_username" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_account_circle_white_36" 
    android:drawablePadding="10dp" 
    android:drawableStart="@drawable/ic_account_circle_white_36" 
    android:gravity="center_vertical" 
    android:text="Username" 
    android:textAllCaps="false" 
    android:textSize="18sp" /> 

<TextView 
    android:id="@+id/fragment_person_personname" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_account_circle_white_36" 
    android:drawablePadding="10dp" 
    android:drawableStart="@drawable/ic_account_circle_white_36" 
    android:gravity="center_vertical" 
    android:text="Person name" 
    android:textAllCaps="false" 
    android:textSize="18sp" /> 

<TextView 
    android:id="@+id/fragment_person_dob" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_account_circle_white_36" 
    android:drawablePadding="10dp" 
    android:drawableStart="@drawable/ic_account_circle_white_36" 
    android:gravity="center_vertical" 
    android:text="Date of birth" 
    android:textAllCaps="false" 
    android:textSize="18sp" /> 

<TextView 
    android:id="@+id/fragment_person_location_country" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_account_circle_white_36" 
    android:drawablePadding="10dp" 
    android:drawableStart="@drawable/ic_account_circle_white_36" 
    android:gravity="center_vertical" 
    android:text="Country" 
    android:textAllCaps="false" 
    android:textSize="18sp" /> 

</LinearLayout> 

Temel olarak, sadece ilk TextView'i görüyorum, geri kalanını görmek için kullanıcının artık alt sayfayı daha fazla sürüklemesi gerekiyor. Aynı anda onCreateView ve onCreateDialog uygulamaması gerektiği (LinearLayout yükseklik seti için wrap_content olsa bile.)

3) PersonBottomSheetFragment.java

public class PersonBottomSheetFragment extends BottomSheetDialogFragment 
    implements LoaderManager.LoaderCallbacks<Cursor> { 

    public final int PERSONBOTTOMSHEETFRAGMENT_LOADER = 18567; // TODO 


    TextView usernameView; 
    TextView personnameView; 
    TextView dobView; 
    TextView locationCountryView; 

    public PersonBottomSheetFragment() { 
     ; 
    } 

    public static PersonBottomSheetFragment newInstance(int personid) { 
     PersonBottomSheetFragment frag = new PersonBottomSheetFragment(); 
     Bundle argsBundle = new Bundle(); 
     argsBundle.putInt("personid", personid); 
     frag.setArguments(argsBundle); 
     return frag; 
    } 

    @Override 
    public void setArguments(Bundle args) { 
     super.setArguments(args); 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

     View view = inflater.inflate(R.layout.fragment_person_bottom_sheet, null); 
     usernameView = (TextView) view.findViewById(R.id.fragment_person_username); 
     personnameView = (TextView) view.findViewById(R.id.fragment_person_personname); 
     dobView = (TextView) view.findViewById(R.id.fragment_person_dob); 
     locationCountryView = (TextView) view.findViewById(R.id.fragment_person_location_country); 

     getLoaderManager().initLoader(PERSONBOTTOMSHEETFRAGMENT_LOADER, null, this); 

     return view; 
    } 

    @Override 
    public Loader<Cursor> onCreateLoader(int i, Bundle bundle) { 

     Uri personsWithIDUri = DataContract.PersonsEntry.buildPersonsUri(getArguments().getInt("personid")); 

     return new CursorLoader(getActivity(), 
       personsWithIDUri, 
       UserFragment.PERSONFRAGMENT_COLUMNS, 
       null, 
       null, 
       null); 
    } 

    @Override 
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) { 

     if (data == null || !data.moveToFirst()) { 
      // null or empty cursor 
      return; 
     } 

     usernameView.setText(data.getString(UserFragment.COL_PERSONS_USERNAME)); 
     personnameView.setText(data.getString(UserFragment.COL_PERSONS_PERSONNAME)); 
     dobView.setText(data.getString(UserFragment.COL_PERSONS_DOB)); 
     locationCountryView.setText(data.getString(UserFragment.COL_PERSONS_LOCATION_COUNTRY)); 
    } 

    @Override 
    public void onLoaderReset(Loader<Cursor> loader) { 

    } 
} 

cevap

0

(onCreateDialogBottomSheetDialogFragment tarafından uygulanmaktadır).

yerine bunu deneyin: Hiçbir noktada

@NonNull 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState); 
    View view = inflater.inflate(R.layout.fragment_person_bottom_sheet, null); 
    usernameView = (TextView) view.findViewById(R.id.fragment_person_username); 
    personnameView = (TextView) view.findViewById(R.id.fragment_person_personname); 
    dobView = (TextView) view.findViewById(R.id.fragment_person_dob); 
    locationCountryView = (TextView) view.findViewById(R.id.fragment_person_location_country); 

    getLoaderManager().initLoader(PERSONBOTTOMSHEETFRAGMENT_LOADER, null, this); 
    dialog.setContentView(view); 
    return dialog; 
} 
+0

ben hem uygulamaya çalışıyorum. OnCreateView kullanmamın nedeni: DialogFragment dokümantasyonunda görebileceğiniz gibi, içeriği belirli durumlarda gömülü parça olarak kullanabilirsiniz (http://developer.android.com/reference/android/app/DialogFragment. html # DialogOrEmbed). Bunun, karşılaştığım asıl sorunu nasıl çözdüğünü de göremiyorum. – CounterFlame

+0

Üst sınıf, onCreateDialog –

+0

uygular. Resmi belgelerinde de görüldüğü gibi, hem tho hem de kullanırken sorun yoktur. – CounterFlame

İlgili konular