我寫了一個登錄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