gpt4 book ai didi

java - 有关 BottomSheetDialog 可见性的问题

转载 作者:行者123 更新时间:2023-12-02 05:45:03 25 4
gpt4 key购买 nike

我的 showUpdateDialog 方法似乎有问题。应用程序运行时,没有出现对话框。

检查 XML 文件是否存在重复/冲突的名称。

没有记录异常。

XML 文件:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="6dp"
tools:layout_editor_absoluteY="8dp">

<android.support.design.widget.TextInputEditText
android:id="@+id/etUpdateUserName"
android:hint="Your Name"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.TextInputEditText
android:id="@+id/etUpdateUserAddress"
android:hint="Your Address"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:id="@+id/btn_update"
android:background="@drawable/custom_button_style"
android:fontFamily="casual"
android:text="Update Information"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>

</android.support.design.widget.TextInputLayout>'


</LinearLayout>

我的MainActivity,包括showUpdateDialog方法:

public class HomeActivity extends AppCompatActivity {

@BindView(R.id.bottom_navigation)
BottomNavigationView bottomNavigationView;

CollectionReference userRef;

BottomSheetDialog bottomSheetDialog;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(HomeActivity.this);


userRef = FirebaseFirestore.getInstance().collection("User");



if(getIntent() !=null)
{
boolean isLogin = getIntent().getBooleanExtra(Common.IS_LOGIN, false);
if(isLogin)
{

AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(final Account account) {
if(account !=null)
{
DocumentReference currentUser =
userRef.document(account.getEmail().toString());
currentUser.get()
.addOnCompleteListener(new
OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull
Task<DocumentSnapshot> task) {
if(task.isSuccessful())
{
DocumentSnapshot userSnapshot =
task.getResult();
if(!userSnapshot.exists())
{

showUpdateDialog(account.getEmail().toString());
}

}
}
});
}
}




@Override
public void onError(AccountKitError accountKitError) {
Toast.makeText(HomeActivity.this,
""+accountKitError.getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}


bottomNavigationView.setOnNavigationItemSelectedListener(new
BottomNavigationView.OnNavigationItemSelectedListener() {
Fragment fragment = null;
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
if(menuItem.getItemId() == R.id.nav_home)
fragment = new HomeFragment();
else if(menuItem.getItemId() == R.id.nav_shopping)
fragment = new ShoppingFragment();

return loadFragment(fragment);
}
});


bottomNavigationView.setSelectedItemId(R.id.nav_home);

}

private boolean loadFragment(Fragment fragment) {
if(fragment !=null)
{

getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
fragment)
.commit();
return true;
}
return false;
}

private void showUpdateDialog(final String email)
{
bottomSheetDialog = new BottomSheetDialog(HomeActivity.this);
bottomSheetDialog.setTitle("One last step...");
bottomSheetDialog.setCanceledOnTouchOutside(false);
bottomSheetDialog.setCancelable(false);
View sheetView =
getLayoutInflater().inflate(R.layout.layout_update_user_information, null);

Button btn_update = (Button)sheetView.findViewById(R.id.btn_update);
final TextInputEditText edit_name =
(TextInputEditText)sheetView.findViewById(R.id.etUpdateUserName);
final TextInputEditText edit_address =
(TextInputEditText)sheetView.findViewById(R.id.etUpdateUserAddress);

btn_update.setOnClickListener(new View.OnClickListener() {


@Override
public void onClick(View v)
{

User user = new User(edit_name.getText().toString(),
edit_address.getText().toString(),
email);
userRef.document(email)
.set(user)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
bottomSheetDialog.dismiss();

Toast.makeText(HomeActivity.this, "Details
updated", Toast.LENGTH_SHORT);
}
}) .addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e)
{

bottomSheetDialog.dismiss();
Toast.makeText(HomeActivity.this, ""+e.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
}
});

bottomSheetDialog.setContentView(sheetView);
bottomSheetDialog.show();


}




}

我希望显示bottomSheetDialogBox,从而夸大layout_update_user_information。

最佳答案

这可能是因为您没有使用正确的上下文来显示对话框

在方法的第一行

bottomSheetDialog = new BottomSheetDialog(this);

你的Context的引用在哪里?

它必须是您的 Activity 或 Fragment 的上下文

尝试像这样更改您的方法参数:

private void showUpdateDialog(Context context, final String email)

并将正确的上下文传递给您的方法,例如

showUpdateDialog(YourActivityClassName.this,"emailAddress");

showUpdateDialog(YourFragmentClassName.this,"emailAddress");

附:确保您从 UI 线程调用您的方法:

runOnUiThread(new Runnable(){
public void run() {
showUpdateDialog(HomeActivity.this,email);
}
});

关于java - 有关 BottomSheetDialog 可见性的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56103119/

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