我写了一个登录xml页面,并且正在检查用户是否有资格通过Firebase数据库登录。现在输入用户名和密码后,我点击“登录”按钮。在此之后加载主页需要几秒钟的时间。所以我想要显示一个进度条,该进度条在那段时间内旋转并停止打开主页。“Binary XML file android.widget.ProgressBar can not to cast to android.view.ViewGroup”in progress bar
我对唱歌,在页面布局是:
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.hsports.bandpop.MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/title"
android:text="WEDDING PLANNER"
android:gravity="center"
android:textSize="50dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:paddingTop="100dp"
>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Layout_username"
android:hint="Username"
>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/username"
android:gravity="center"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Layout_password"
android:hint="Password"
>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:gravity="center"
android:inputType="textPassword"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="50dp"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIGN IN"
android:onClick="checkSignIn"
android:gravity="center"
android:id="@+id/SignInButton"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="REGISTER"
android:onClick="registerForm"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ProgressBar>
而且代码上点击“签到”按钮片段:
package com.example.hsports.weddingplanner.Fragments;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.example.hsports.weddingplanner.Activities.FrontPage;
import com.example.hsports.weddingplanner.Activities.WeddingPlanningUsers;
import com.example.hsports.weddingplanner.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
/**
* Created by I324671 on 11/28/2016.
*/
public class SignIn extends Fragment {
SharedPreferences sharedPreferences;
String MyPreferences="loginUserInfo";
ProgressBar afterSignIn;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
final View view=inflater.inflate(R.layout.activity_login_page, container, false);
afterSignIn=(ProgressBar)view.findViewById(R.id.loadingSignIn);
Button checkSignIn=(Button)view.findViewById(R.id.SignInButton);
checkSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
afterSignIn.setVisibility(view.VISIBLE);
final String username = ((TextView) (view.findViewById(R.id.username))).getText().toString();
final String password = ((TextView) (view.findViewById(R.id.password))).getText().toString();
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference reference = database.getReference("Users");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChildren()) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
String usernameFromDB=child.getKey().toString();
String passwordFromDB=child.getValue().toString();
if(username.equals(usernameFromDB)&& password.equals(passwordFromDB))
{
sharedPreferences=getContext().getSharedPreferences(MyPreferences, Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("Username",username);
editor.putString("Password", password);
editor.commit();
afterSignIn.setVisibility(view.GONE);
Intent transferToHome=new Intent(getContext(), FrontPage.class);
startActivity(transferToHome);
break;
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d("The read failed", databaseError.getDetails());
}
});
}
});
return view;
}
}
我马云对执行得到的错误这是: “二进制XML文件android.widget.ProgressBar无法转换为android.view.ViewGroup”。 我该如何解决这个问题。
我收到登录页面上方的进度栏。如何隐藏登录页面,然后显示此进度栏,然后将其重定向到其他页面。 – user3361096