前回の回答でkeichaさんというかたが説明されたかと思いますが、androidで
public static void main(String[] args)
は使えません。
onCreate()
内で質問者さまがxmlで定義したtextviewのidをfindviewbyid()というメソッドでTextview型として取得し、そのインスタンスにsettext('入れたい文字列')
というメソッドを入れます。
質問者さまの前回の質問のxmlを見るとtextview
にidが指定されていなかったようなので、
xml
1<TextView
2 android:layout_width="wrap_content"
3 android:layout_height="wrap_content"
4 app:layout_constraintBottom_toBottomOf="parent"
5 app:layout_constraintLeft_toLeftOf="parent"
6 app:layout_constraintRight_toRightOf="parent"
7 app:layout_constraintTop_toTopOf="parent" />
8
9
にandroid:id="text"
とでも追加し、
activityで
java
1
2import android.support.v7.app.AppCompatActivity;
3import android.os.Bundle;
4
5public class MainActivity extends AppCompatActivity {
6@Override
7 protected void onCreate(Bundle savedInstanceState) {
8 super.onCreate(savedInstanceState);
9 setContentView(R.layout.質問者さまのxmlレイアウトの名前);
10
11 int A;
12 A = 00;
13 Textview a = findviewbyid(R.id.text)
14
15 if (A == 00) {
16 a.settext("総記");
17 }
18 else if (A == 01) {
19 a.settext("百科事典");
20 }//以下略
21
22}
23 }
24
などとやればできるはずです。(今旅行中でスマホから打っているので、メソッドの大文字小文字や行間が適当ですが、そこは適宜修正してください...)