Приложение Г
Пример приложения для переключения между экранами
Листинг MainActivity.java
package ru.omgtu.myapplication; import
android.content.Intent;
import android.support.v7.app.AppCompatActivity; import
android.os.Bundle; import android.view.View; import android.widget.Button;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener{
Button btnNextWindow; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.
activity_main
);
btnNextWindow =(Button) findViewById(R.id.
btnNextWindow
);
btnNextWindow.setOnClickListener(this);
}
@Override
public void onClick(View v) { switch (v.getId())
{ case R.id.
btnNextWindow
:
Intent intent = new Intent(this,NewActivity.class); startActivity(intent);
break; default:
break;
}
}
}
Листинг activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
72
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ru.omgtu.myapplication.MainActivity">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="NextWindow" android:id="@+id/btnNextWindow" />
Листинг activity_new.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="ru.omgtu.myapplication.NewActivity">
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="@string/txtAct2" android:textSize="50sp" />
73
|