I am writing an application for Android. Tell me how to make the transition to the next screen when you press the button?

3 answers 3

startActivity(this, new Intent(this, SecondActivity.class)); 
  • Insert this line in .java, and also create a new class SecontActivity.class? It is possible a little more, I'm just learning)) - Goshka Tarasov
  • 2
    @Gorets, I suspect, comrade asks to explain to him what Java is. - AseN

Actually, in android studio it is done this way - with the right mouse button a new activity is created, after which a new class is also created, the onClick event is assigned to the button and the class name is assigned to it, and the class is inserted

  public void kyrsibtn(View view) { Intent intent; intent = new Intent(MyActivity.this, kyrsi.class); startActivity(intent);} 

    Creating an activity by class name (it may come in handy):

     public class MainActivity extends ListActivity { String listNames[] = { "Test", "TestTest", "TestTestTest" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listNames)); } @Override protected void onListItemClick(ListView list, View view, int position, long id) { super.onListItemClick(list, view, position, id); String testName = listNames[position]; try { Class<?> cl = Class.forName("com.example.myprog." + testName); Intent intent = new Intent(this, cl); startActivity(intent); } catch(ClassNotFoundException e) { } } 

    Well, of course, before using, you need to create Activation Test, TestTest and TestTestTest and register them in the manifest (just a reminder):

      <activity android:label="Test" android:name=".Test" /> <activity android:label="TestTest" android:name=".TestTest" /> <activity android:label="TestTestTest" android:name=".TestTestTest" /> 
    • Thank you, tomorrow I will think about how all this is implemented. - Goshka Tarasov
    • one
      @MDJHD, this is unlikely to be useful to someone. In addition, if you really find fault, in this way almost no one comes in - they use intentions, if everything is so difficult. - AseN