На первой странице все работает нормально, но когда я нажимаю кнопку, загружается вторая страница, но кнопка не появляется ... Нет сбоев или ошибок.
Public void onClick(View v)
{
switch (v.getId())
{
case R.id.button2:
finish();
break;
case R.id.button1:
Intent game1 =new Intent(this, game.class);
this.startActivity(game1);
}
Затем я отображаю страницу 2
public class game extends Activity implements OnClickListener{
public void OnCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.game1);
Button b1= (Button)findViewById(R.id.b1);// Doesn't show up
b1.setOnClickListener(this);
}
public void onClick (View v)
{
switch (v.getId())
{
case R.id.b1:
setResult(RESULT_OK);
finish();
break;
}
}
}
Кнопка не показывается ... и я не понимаю, почему. Любой ответ полезен.
Редактировать: вот XML для игры1
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/white" >
<Button
android:id="@+id/b1"
android:layout_width="100dp"
android:layout_height="50dp"
android:onClick="myClick"
android:text="Exit" />
</LinearLayout>
Редактировать: И макет для основного
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="104dp"
android:layout_height="wrap_content"
android:text="Start" />
<Button
android:id="@+id/button2"
android:layout_width="99dp"
android:layout_height="wrap_content"
android:text="Exit"
android:onClick="myClick"
/>
</LinearLayout>