ボタンが layout.xml で定義されたメイン アプリケーションがあります。
ボタンをクリックしたときに、別のクラスにあるメソッドを呼び出したいのですが、そのクラスで TextView を作成しようとすると、新しい TextView(???) コマンドに引数を指定する必要があります。何をすべきかわからない。
これは皆さんにとっては 2 秒の質問だと思いますが、初心者の私にとっては難しい質問です。
念のため、コードの関連セクションを次に示します。
該当するメイン クラスのセクション:
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
}
メソッドが呼び出されるクラス:
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
}
ちなみに、current_location_numberv と ArrayList の 2 つのパラメーターを doSun2 メソッドに渡さないようにするにはどうすればよいのでしょうか。これらはグローバル "であるべき" ためです (私が C 出身であることがわかります...)。
ご協力ありがとうございました。
そして、あらゆる種類の炎上者の皆さん、そうです、私はこれに対する答えを見つけようとしました...