在我的布局文件 - main.xml(线性布局)中,有 2 个按钮(比如 b1 和 b2)、1 个列表视图和 1 个相对布局。当我单击 b1 时,会生成列表视图VISIBLE
并生成相对布局GONE
。当我单击 b2 时,会生成列表视图GONE
并生成相对布局VISIBLE
。这是代码,
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();
}
}
});
第一次单击 b2 时,Edittext(username) 被锁定(即 setenabled 和 setfocussable 设置为 false)。但是当我单击 b1 然后单击 b2 时,Edittext 没有被锁定,并且 setText 也不存在。这可能是什么原因?