I created a Java file in the same package as my main activity with a class named sup.
Now, I need to use this class in the main activity file.
mainActivity.java:
package com.example.phy.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } sup mola = new sup(this); mola.as(); } sup.java:
package com.example.phy.myapplication; import android.content.Context; import android.widget.Toast; public class sup { public sup(Context context){ CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } void as(Context context){ CharSequence text = "as method"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } Do I have to import the class into mainActivity? How?