gpt4 book ai didi

android - BottomSheetDialogFragment - 如何包装内容并完整显示?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:01 25 4
gpt4 key购买 nike

因此随着 AppCompat 支持库的 v23.2 版本发布,我决定使用 BottomSheetDialogFragment。当我单击 ListView 中的项目时,我一直试图打开底部工作表(与适配器连接,因此它代表一个光标)。单击时,我将光标的 ID 传递给 DialogFragment 并重新查询内容提供程序以填写底部工作表。

这一切似乎工作正常,现在的问题是当底部工作表打开时,我只看到顶部的 TextView,而我希望它显示传递到底部工作表的完整布局。

这是我现在拥有的:

1) 在包含 ListView 的 fragment 中,打开底部工作表对话框:

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>

所以基本上我只看到第一个 TextView,要看到其余部分,用户现在必须将底部工作表进一步向上拖动。 (即使 LinearLayout 具有高度设置的 wrap_content。)

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) {

}
}

最佳答案

你不应该同时实现onCreateViewonCreateDialog(onCreateDialog是由BottomSheetDialogFragment实现的) .

尝试这样做:

@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;
}

关于android - BottomSheetDialogFragment - 如何包装内容并完整显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35817538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com