Reputation: 2821
I have a linearlayout with three icons as below
<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" />
initially the middle icon is hidden (android:visibility="gone") I have a login screen..when the login i success I want the icon to be visible ..tried as below..but itz not working
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();
}
});
Upvotes: 0
Views: 2504
Reputation: 6856
Try this,
ImageView details;
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);
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.");
details.setVisibility(View.VISIBLE);
} else {
lblResult.setText("password doesn't match.");
}
finish();} });
Upvotes: 0
Reputation: 5243
You should make the ImageView details object a class variable, so that it can definitely be accessed by your listener later.
Upvotes: 2