Только начал изучение java.
Такой вопрос:
Есть приложение в котором после нажатия на кнопку меняется textView
Код: Выделить всё
package com.a5project.a9project;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("Работает");
}
});
}
}
Код: Выделить всё
Random rand = new Random();
int q;
q = rand.nextInt(22);
if (q == 1) System.out.print("Текст");
else if (q == 2) System.out.print("Текст2");
else if (q == 3) System.out.print("Текст3");
else if (q == 4) System.out.print("Текст4");
else if (q == 5) System.out.print("Текст5");
else if (q == 6) System.out.print("Текст6");
else if (q == 7) System.out.print("Текст7");
else if (q == 8) System.out.print("Текст8");
else if (q == 9) System.out.print("Текст9");
else if (q == 10) System.out.print("Текст10");
else if (q == 11) System.out.print("Текст11");
else if (q == 12) System.out.print("Текст12");
else if (q == 13) System.out.print("Текст13");
else if (q == 14) System.out.print("Текст14");
else if (q == 15) System.out.print("Текст15");
else if (q == 16) System.out.print("Текст16");
else if (q == 17) System.out.print("Текст17");
else if (q == 18) System.out.print("Текст18");
else if (q == 19) System.out.print("Текст19");
else if (q == 20) System.out.print("Текст20");
else if (q == 21) System.out.print("Текст21");
else if (q == 22) System.out.print("Текст22");
Мучаюсь 2 день, куда только переменные не пихал.