有关提示的代码不生效
来源:7-1 案例完善
weibo_小赵Angie_0
2021-08-09 22:21:41
相关代码:activity
import android.widget.ProgressBar;
import android.widget.Toast;
public class mnRegisterActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mn_register);
}
public void myClick(View v){
EditText nameEdt=findViewById(R.id.password);
EditText passEdt=findViewById(R.id.username);
final ProgressBar psbar=findViewById(R.id.progressBar);
String name=nameEdt.getText().toString();
String pass=passEdt.getText().toString();
if(name.equals("")||pass.equals("")){
Toast.makeText(this,"请输入用户名或密码",Toast.LENGTH_SHORT);
}else{
psbar.setVisibility(View.VISIBLE);
new Thread(){
public void run(){
for(int i=0;i<100;i++){
psbar.setProgress(i);
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
}
}
相关代码:layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="Sign Up"
android:layout_marginTop="70dp"
android:layout_height="wrap_content">
</TextView>
<TextView
android:layout_width="wrap_content"
android:text="Imooc Imooc Imooc Imooc\nImooc Imooc Imooc"
android:layout_margin="20dp"
android:gravity="center_horizontal"
android:layout_height="wrap_content">
</TextView>
<ImageView
android:layout_width="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_height="wrap_content">
</ImageView>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="invisible"
android:layout_margin="10dp"
android:layout_height="wrap_content">
</ProgressBar>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:hint="请输入用户名"
android:gravity="center_horizontal">
</EditText>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:hint="请输入密码"
android:gravity="center_horizontal"
android:inputType="textPassword">
</EditText>
<Button
android:id="@+id/butn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginRight="30dp"
android:background="#31AC65"
android:onClick="myClick"
android:text="register"></Button>
</LinearLayout>
问题描述:点击按钮register以后提示没有生效,只有进度条生效
1回答
LovelyChubby
2021-08-10
Activity 中的代码只能看到,你读取了两个输入框的文本并进行判断。
如果都不为空则显示进度条,且开始线程更新进度值,没有看到你说的提示无效的代码呢。
相似问题