외부 java class 에서 main activity 의 콘트롤 findViewById
http://www.androidpub.com/428203
1.
package
SoundExam.Android;
1.
import
android.app.Activity;
2.
import
android.os.Bundle;
3.
import
android.view.View;
4.
import
android.widget.Button;
01.
public
class
SoundExamActivity
extends
Activity {
02.
/** Called when the activity is first created. */
03.
@Override
04.
public
void
onCreate(Bundle savedInstanceState) {
05.
super
.onCreate(savedInstanceState);
06.
setContentView(R.layout.main);
07.
SoundExam.InitExam(
this
);
08.
}
09.
}
그리고 여기서 참조하는 SoundExam 클래스는 다음과 같습니다.
1.
package
SoundExam.Android;
1.
public
class
SoundExam {
2.
static
Context mMain;
1.
public
static
void
InitExam(Context main) {
2.
mMain = main;
3.
}
1.
public
static
void
NextSound() {
1.
((EditText) ((Activity) mMain).findViewById(R.id.txtSound)).setText(
"Downloaded!"
);
2.
}
3.
4.
}
1.
package
SoundExam.Android;
1.
import
android.app.Activity;
2.
import
android.os.Bundle;
3.
import
android.view.View;
4.
import
android.widget.Button;
01.
public
class
SoundExamActivity
extends
Activity {
02.
/** Called when the activity is first created. */
03.
@Override
04.
public
void
onCreate(Bundle savedInstanceState) {
05.
super
.onCreate(savedInstanceState);
06.
setContentView(R.layout.main);
07.
SoundExam.InitExam(
this
);
08.
}
09.
}
1.
package
SoundExam.Android;
1.
public
class
SoundExam {
2.
static
Context mMain;
1.
public
static
void
InitExam(Context main) {
2.
mMain = main;
3.
}
1.
public
static
void
NextSound() {
1.
((EditText) ((Activity) mMain).findViewById(R.id.txtSound)).setText(
"Downloaded!"
);
2.
}
3.
4.