问题描述
- 如何以程序化的方式隐藏 imageview
- 我创建了一个 linearlayout,有三个 icons:
<ImageView android:id=""@+id/cities"" android:layout_width=""wrap_content"" android:layout_height=""wrap_content android:src=""@drawable/city"" /> <ImageView android:id=""@+id/red"" android:layout_width=""wrap_content"" android:layout_height=""wrap_content"" android:src=""@drawable/red"" android:visibility=""gone"" /> <ImageView android:id=""@+id/deal"" android:layout_width=""wrap_content"" android:layout_height=""wrap_content"" android:src=""@drawable/deal"" />
最初中间的图标是隐藏的(android:visibility=""gone""),我想在登录界面上登录成功时,图标显示出来。下面的方法不对,如何实现?
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fyelogin); etPassword = (EditText)findViewById(R.id.password); btnLogin = (Button)findViewById(R.id.login_button); btnCancel = (Button)findViewById(R.id.cancel_button); lblResult = (TextView)findViewById(R.id.result); final ImageView details = (ImageView)findViewById(R.id.red); btnLogin.setOnClickListener(new OnClickListener() { public void onClick(View v) { String password = etPassword.getText().toString(); if(password.equals(""guest"")){ lblResult.setText(""password successful.""); giving error @ this line -----> details.setVisibility(View.VISIBLE); } else { lblResult.setText(""password doesn't match.""); } finish();} });
解决方案
你后面有个finish()方法,Activity关闭了就是显示了ImageView也看不到
把finish()去掉就能看到了
时间: 2025-01-21 11:26:16