I’m pretty new to Android but I have some experience (and a bit rusty with) Java and OOP.
Basically what my app does is when you press a button, led’s or “images” will flash.
I’m trying to divide up my project into multiple files where I can just import a java file to use the class’s functions but I’m unsure on how to do that…
I have two files. 1) HelloFormStuff.java (this is like the main one), and 2) led_functions.java
In HelloFormStuff I put:
import com.example.helloformstuff.led_functions
// com.example.helloformstuff is the package
Example of code.. HelloFormStuff.java
public class HelloFormStuff extends Activity {
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
currentMode.setText("Button 1 Pressed");
led_circleBusy();
}
});
}
}
And in led_functions.java…
public class led_functions extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView LED_1;
LED_1 = (ImageView)findViewById(R.id.LED_1);
@Override
public void led_circleBusy()
{
LED_1.setVisibility(View.INVISIBLE);
}
}
An error I get is: The method led_circleBusy() is undefined for the type new View.OnClickListener(){}
So I’m asking is how to implement my other functions from other files.
Thanks.
-Paul
PS: I’ve been looking at sample code and if you’re wondering why I put something like an “@Override” where it’s not needed, just ignore it.. I’ve been trying random things :l
You can do the following from your
HelloFormStuffclass.Then get rid of the
@Overridefrom above theled_circleBusy()method. You shouldn’t really be calling other Activity’s methods like that though. Isled_functionsreally an Activity/UI class? If not, remove theextends Activity, addLED_1toHelloFormStuffand then pass it as a parameter toled.led_circleBusy(ImageView led1).