In my layout file – main.xml(linear layout), there are 2 buttons(say b1 and b2), 1 listview and 1 relative layout. When I click on b1, list view is made VISIBLE and the relative layout is made GONE. When I click on b2, listview is made GONE and relative layout is made VISIBLE. Here is the code,
b1.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
try{ListView listView = (ListView) Home.this.findViewById(R.id.mylist);
listView.setTextFilterEnabled(true);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" ,"asdsad","asdsdsa","asdasdsa"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
R.layout.list_item,values);
// Assign adapter to ListView
RelativeLayout rl=(RelativeLayout) findViewById(R.id.rl1);
rl.setVisibility(8);
listView.setAdapter(adapter);
listView.setVisibility(0);}
catch(Exception e){Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();}
}
});<br>
b2.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
try
{
ListView ls=(ListView) findViewById(R.id.mylist);
ls.setVisibility(8);
RelativeLayout rl=(RelativeLayout) findViewById(R.id.rl1);
getLayoutInflater().inflate(R.layout.creategroup,rl,true);
rl.setVisibility(0);
EditText username=(EditText) findViewById(R.id.group_owner_fill);
username.setText(userid);
username.setEnabled(false);
username.setFocusable(false);
boolean t=username.isEnabled();
String s=new Boolean(t).toString();
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
}
}
});
First time when I click b2, the Edittext(username) is locked(i.e setenabled and setfocussable are made false). But when I click b1 and then click b2, the Edittext is not locked and also setText is not there. What can be the possible reason for this?
Instead of setting visibility, i would suggest you to implement ViewFlipper. Because ViewFlipper allows us to flip views whenever user want.
In code, you can flip the view by using setDisplayedChild() method. FYI, RelativeLayout is the child 1. so you have to write down
flipper.setDisplayedChild(1)