当单击登录按钮时,我试图让我的 ProgressBar 变为可见。这是我的活动 XML:
<RelativeLayout 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:gravity="center_vertical"
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=".MainActivity" >
<EditText
android:id="@+id/txtView_UserName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:hint="@string/login_username_hint">
<requestFocus />
</EditText>
<EditText
android:id="@+id/txtView_Password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtView_UserName"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:hint="@string/login_password_hint"
android:inputType="textPassword" />
<Button
android:id="@+id/button_LogIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtView_UserName"
android:layout_below="@+id/txtView_Password"
android:layout_marginTop="10dp"
android:onClick="logIn"
android:text="@string/login_button" />
<CheckBox
android:id="@+id/checkbox_RememberPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtView_Password"
android:layout_below="@+id/button_Login"
android:layout_marginTop="15dp"
android:text="@string/remember_my_password" />
<CheckBox
android:id="@+id/checkbox_LogMeInAutomatically"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkbox_RememberPassword"
android:layout_below="@+id/checkbox_RememberPassword"
android:layout_marginTop="-5dp"
android:text="@string/log_me_in_automatically" />
<ProgressBar
android:id="@+id/progressBar_LogIn"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/checkbox_LogMeInAutomatically"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:visibility="invisible" />
<TextView
android:id="@+id/txtView_Version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="18dp"
android:text="@string/version_number" />
</RelativeLayout>
这是我试图在代码中将其更改为 VISIBLE 的地方。
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//Get Views and Buttons
EditText txt_Username = (EditText) findViewById(R.id.txtView_UserName);
EditText txt_Password = (EditText) findViewById(R.id.txtView_Password);
Button btn_LogIn = (Button) findViewById(R.id.button_LogIn);
CheckBox chkbox_RememberMyPassword = (CheckBox) findViewById(R.id.checkbox_RememberPassword);
CheckBox chkbox_LogMeInAutomatically = (CheckBox) findViewById(R.id.checkbox_LogMeInAutomatically);
ProgressBar progressbar_LogIn = (ProgressBar) findViewById(R.id.progressBar_LogIn);
public void logIn() {
progressbar_LogIn.setVisibility(0);
}
}
该程序在没有呈现我的 Activity 视图的情况下崩溃。有任何想法吗?