在我的应用程序中,我试图在 RealViewSwitcher 中切换两个透明按钮的可见性(我知道这是相当骇人听闻的)。我正在根据 RealViewSwitcher 的当前页面更改可见性。我可以让第一个按钮工作,但第二个按钮永远不会激活。这是我的代码:
///////////////
if(realViewSwitcher.getCurrentScreen() == 0)
{
final Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://www.test.com"));
startActivity(intent);
btn1.setVisibility(View.GONE);
}
});
}
else if(realViewSwitcher.getCurrentScreen() == 2)
{
final Button btn2 = (Button)findViewById(R.id.btn2);
btn2.setVisibility(0);
btn2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { "info@email.com" };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_TEXT, "body");
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");
}
});
}
///////////////
//end
/////////////////////
这是xml
<Button
android:id="@+id/btn1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"/>
<Button
android:id="@+id/btn2"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@null"
android:visibility="gone"/>