I have a main application with a button defined in layout.xml.
When I click on the button, I want to call a method located in another class, and when I try to create a TextView in that class, I must provide an argument to the new TextView(???) command, and I don't know what to do.
I reckon that this is a 2 seconds question for you folks, and for me, newbiiie as it is, it is a tough one.
Just in case, here are the relevant sections of code:
The section of the main class that is applicable:
public class MainActivity extends Activity {
public DateAndTime cur_datetime = new DateAndTime();
public LongLat cur_longlat = new LongLat();
public int current_location_number = 0;
public ArrayList<LocationInfo> locations = null;
Button doSunButton;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenersForButtons();
dosomething();
}
public void addListenersForButtons()
{
doSunButton = (Button) findViewById(R.id.dosun_button_id);
doSunButton.setOnClickListener( new OnClickListener()
{
@Override
public void onClick(View arg0)
{
DoSun myDoSun = new DoSun();
Log.v("button", "Am I really calling from the button function...");
myDoSun.doSun2(locations, current_location_number);
} // end of dosun on click on dosun_id button
); // end of define listener
} // end of addListenersForButtons(0) method
}
The class whose method is called:
package com.example.sunandmoon;
import java.util.ArrayList;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
public class DoSun extends Activity{
public void doSun2(ArrayList<LocationInfo> locations, int current_location_number)
{
//Log.v("doSun", "Am I really there!");
TextView textViewsunrise = new TextView(??????);
textViewsunrise = (TextView) findViewById(R.id.sunrise_id);
((TextView)textViewsunrise).setText("From DoSun2! " + locations.get(current_location_number).getnameGiven());
} // end of doSun(0) method
}
And by the way, I also wonder how I could avoid passing the two parameters current_location_numberv and ArrayList locations to the doSun2 method, since they "should be" globals (you can see that I come from C...).
Thank you for your help.
And to you flamers of all kinds, yes, I have tried to find an answer to this...