I do according to the textbook, the first android is literally the first program. should choose the type of beer after clicking on the button to produce the desired grade. the text has changed under its realities. Instead of the necessary line it always gives the second
else { brands.add("Слишком сложно"); brands.add("Давай еще раз"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClick123(View view) { TextView brands = (TextView) findViewById(R.id.brands); Spinner color = (Spinner) findViewById(R.id.color); String beerType = String.valueOf(color.getSelectedItemId()); List<String> brandsList = expert.getBrands(beerType); StringBuilder brandsFormatted =new StringBuilder(); for (String brand : brandsList){ brandsFormatted.append(brand).append("\n");} brands.setText(brandsFormatted); } }
second activation
List<String> getBrands(String color) { List<String> brands =new ArrayList<>(); if (color.equals("тупые все вокруг?")){ brands.add("Нет,это ты тупой"); brands.add("Попробуй еще раз");} else { brands.add("Слишком сложно"); brands.add("Давай еще раз");} return brands;
?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="20dp" android:paddingBottom="20dp" tools:context=".MainActivity" > <Spinner android:id="@+id/color" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:entries="@array/SpinnerText"/> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@id/color" android:layout_alignStart="@id/color" android:layout_below="@id/color" android:layout_marginTop="20dp" android:text="@string/but" android:onClick="onClick123" /> <TextView android:id="@+id/brands" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_alignLeft="@id/button1" android:layout_alignStart="@id/button1" android:layout_below="@id/button1" android:layout_marginTop="20dp" android:text="@string/brands" /> </RelativeLayout>
<resources> <string name="app_name">beershow</string> <string name="but">Не тупи,Жми сюда</string> <string name="brands">Это не сложно,тут всего одна кнопка</string> <string-array name="SpinnerText"> <item>ты тупой?</item> <item>тупые все вокруг?</item> <item>ни кто не тупой?</item> <item>сам ты тупой!</item> <item>сколько можно одно и тоже. </item> </string-array>
strings and actviti maine also attached