Skip to content

Instantly share code, notes, and snippets.

@abusoid
Last active May 28, 2018 10:48
Show Gist options
  • Save abusoid/a7206f1532a73e40fc649a96439efda2 to your computer and use it in GitHub Desktop.
Save abusoid/a7206f1532a73e40fc649a96439efda2 to your computer and use it in GitHub Desktop.
Энциклопедия аквариумиста приложение на Андроид
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/freshwater"
style="@style/CategoryStyle"
android:background="@color/category_freshwater"
android:text="@string/freshwater_category"
android:onClick="freshwaterClick"/>
<TextView
android:id="@+id/saltwater"
style="@style/CategoryStyle"
android:background="@color/category_saltwater"
android:text="@string/saltwater_category"
android:onClick="saltwaterClick"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/calc_category"
style="@style/CategoryStyle"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:background="@color/category_calc"
android:onClick="calcClick"
android:text="@string/calc_category" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
package com.mogilevskiydenis.aquariumvici;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class calcMenu extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_menu);
TextView volume = (TextView) findViewById(R.id.freshwater_fish);
volume.setText("Объем аквариума");
TextView cheto = (TextView) findViewById(R.id.freshwater_plant);
cheto.setText("Еще чего-то");
TextView chetoto = (TextView) findViewById(R.id.freshwater_invertebrates);
chetoto.setText("И еще чего-то");
}
//Выбор во втором меню раздела Рыбы
public void freshwaterFishClick(View view){
Intent calcVolume = new Intent(calcMenu.this, Volume.class);
startActivity(calcVolume);
}
//Выбор во втором меню раздела Растения
public void freshwaterPlantClick(View view){
}
public void freshwaterInvertebratesClick(View view){
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/description_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TITLE" />
<ImageView
android:id="@+id/description_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher_round"/>
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Давай протестируем, что у нас получается. ХМММ МММММММ МММММММММММ, а что будет если добавить побольше текста"/>
</LinearLayout>
package com.mogilevskiydenis.aquariumvici;
public class Item {
//Название рыбы
private String mName;
//id картинки к рыбе
private int mImageResourceId = NO_IMAGE_PROVIDED;
//константа на случай если нет изображения к рыбке
private static final int NO_IMAGE_PROVIDED = -1;
private String mDescriptionText;
public Item(String Name, int imageResourceId, String descriptionText){
mName = Name;
mImageResourceId = imageResourceId;
mDescriptionText = descriptionText;
}
public String getName() { return mName; }
public int getImageResourceId(){ return mImageResourceId; }
public boolean hasImage() {
return mImageResourceId != NO_IMAGE_PROVIDED;
}
public String getDescriptionText () {
return mDescriptionText;
}
}
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" />
package com.mogilevskiydenis.aquariumvici;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
public class ItemAdapter extends ArrayAdapter<Item> {
//Id фона текста
private int mColorResourceId;
public ItemAdapter(Context context, ArrayList<Item> items, int colorResourceId) {
super(context, 0, items);
mColorResourceId = colorResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
// Get the {@link Word} object located at this position in the list
Item currentItem = getItem(position);
// Find the TextView in the list_item.xml layout with the ID name_text_view.
TextView miwokTextView = (TextView) listItemView.findViewById(R.id.name_text_view);
miwokTextView.setText(currentItem.getName());
// Find the ImageView in the list_item.xml layout with the ID image.
ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
// Check if an image is provided for this word or not
if (currentItem.hasImage()) {
// If an image is available, display the provided image based on the resource ID
imageView.setImageResource(currentItem.getImageResourceId());
// Make sure the view is visible
imageView.setVisibility(View.VISIBLE);
} else {
// Otherwise hide the ImageView (set visibility to GONE)
imageView.setVisibility(View.GONE);
}
// Set the theme color for the list item
View textContainer = listItemView.findViewById(R.id.text_container);
// Find the color that the resource ID maps to
int color = ContextCompat.getColor(getContext(), mColorResourceId);
// Set the background color of the text container View
textContainer.setBackgroundColor(color);
// Return the whole list item layout (containing 2 TextViews) so that it can be shown in
// the ListView.
return listItemView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tan_background"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal">
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height" />
<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/image">
<TextView
android:id="@+id/name_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
package com.mogilevskiydenis.aquariumvici;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void freshwaterClick(View view){
Intent freshwaterIntent = new Intent(MainActivity.this, SecondMenu.class);
// Start the new activity
startActivity(freshwaterIntent);
}
public void saltwaterClick(View view){
Intent freshwaterIntent = new Intent(MainActivity.this, SaltwaterSecondMenu.class);
// Start the new activity
startActivity(freshwaterIntent);
}
public void calcClick(View view){
Intent freshwaterIntent = new Intent(MainActivity.this, calcMenu.class);
// Start the new activity
startActivity(freshwaterIntent);
}
}
package com.mogilevskiydenis.aquariumvici;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class SaltwaterSecondMenu extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_menu);
}
//Выбор во втором меню раздела Рыбы
public void freshwaterFishClick(View view){
/* Intent freshwaterIntent = new Intent(SecondMenu.this, FishesMenu.class);
// Start the new activity
startActivity(freshwaterIntent);*/
setContentView(R.layout.item_menu_list);
//Создание списка
final ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Морской Неон", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Морской Меченосец", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Морской Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Морской Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Морской Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Морской Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Морской Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Морской Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
//Создание ссылки на{@link ItemAdapter}, который дает параметры создания листа
ItemAdapter adapter = new ItemAdapter(this, items, R.color.category_saltwater);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// реализация кликабельности каждого элемента ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
setContentView(R.layout.description_window);
TextView title = (TextView) findViewById(R.id.description_title);
title.setText(items.get(i).getName());
// Выводим сообщение с текстом выбранного элемента
//Toast.makeText(getApplicationContext(), "Вы выбрали: " + Name, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView) findViewById(R.id.description_image);
image.setImageResource(items.get(i).getImageResourceId());
TextView description = (TextView) findViewById(R.id.description_text);
description.setText(items.get(i).getDescriptionText());
}
});
}
//Выбор во втором меню раздела Растения
public void freshwaterPlantClick(View view){
setContentView(R.layout.item_menu_list);
//Создание списка
final ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Валинснерия", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Роголистник", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
//Создание ссылки на{@link ItemAdapter}, который дает параметры создания листа
ItemAdapter adapter = new ItemAdapter(this, items, R.color.category_freshwater);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// реализация кликабельности каждого элемента ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
setContentView(R.layout.description_window);
TextView title = (TextView) findViewById(R.id.description_title);
title.setText(items.get(i).getName());
// Выводим сообщение с текстом выбранного элемента
//Toast.makeText(getApplicationContext(), "Вы выбрали: " + Name, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView) findViewById(R.id.description_image);
image.setImageResource(items.get(i).getImageResourceId());
TextView description = (TextView) findViewById(R.id.description_text);
description.setText(items.get(i).getDescriptionText());
}
});
}
public void freshwaterInvertebratesClick(View view){
setContentView(R.layout.item_menu_list);
//Создание списка
final ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
//Создание ссылки на{@link ItemAdapter}, который дает параметры создания листа
ItemAdapter adapter = new ItemAdapter(this, items, R.color.category_calc);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// реализация кликабельности каждого элемента ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
setContentView(R.layout.description_window);
TextView title = (TextView) findViewById(R.id.description_title);
title.setText(items.get(i).getName());
// Выводим сообщение с текстом выбранного элемента
//Toast.makeText(getApplicationContext(), "Вы выбрали: " + Name, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView) findViewById(R.id.description_image);
image.setImageResource(items.get(i).getImageResourceId());
TextView description = (TextView) findViewById(R.id.description_text);
description.setText(items.get(i).getDescriptionText());
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/freshwater_fish"
style="@style/CategoryStyle"
android:background="@color/category_saltwater"
android:text="Рыбы"
android:onClick="freshwaterFishClick"/>
<TextView
android:id="@+id/freshwater_plant"
style="@style/CategoryStyle"
android:background="@color/category_freshwater"
android:text="Растения"
android:onClick="freshwaterPlantClick"/>
<TextView
android:id="@+id/freshwater_invertebrates"
style="@style/CategoryStyle"
android:background="@color/category_calc"
android:text="Беспозвоночные"
android:layout_alignParentBottom="true"
android:onClick="freshwaterInvertebratesClick"/>
</LinearLayout>
package com.mogilevskiydenis.aquariumvici;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class SecondMenu extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_menu);
}
//Выбор во втором меню раздела Рыбы
public void freshwaterFishClick(View view){
/* Intent freshwaterIntent = new Intent(SecondMenu.this, FishesMenu.class);
// Start the new activity
startActivity(freshwaterIntent);*/
setContentView(R.layout.item_menu_list);
//Создание списка
final ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Неон", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Меченосец", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
//Создание ссылки на{@link ItemAdapter}, который дает параметры создания листа
ItemAdapter adapter = new ItemAdapter(this, items, R.color.category_saltwater);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// реализация кликабельности каждого элемента ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
setContentView(R.layout.description_window);
TextView title = (TextView) findViewById(R.id.description_title);
title.setText(items.get(i).getName());
// Выводим сообщение с текстом выбранного элемента
//Toast.makeText(getApplicationContext(), "Вы выбрали: " + Name, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView) findViewById(R.id.description_image);
image.setImageResource(items.get(i).getImageResourceId());
TextView description = (TextView) findViewById(R.id.description_text);
description.setText(items.get(i).getDescriptionText());
}
});
}
//Выбор во втором меню раздела Растения
public void freshwaterPlantClick(View view){
setContentView(R.layout.item_menu_list);
//Создание списка
final ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Валинснерия", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Роголистник", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
//Создание ссылки на{@link ItemAdapter}, который дает параметры создания листа
ItemAdapter adapter = new ItemAdapter(this, items, R.color.category_freshwater);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// реализация кликабельности каждого элемента ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
setContentView(R.layout.description_window);
TextView title = (TextView) findViewById(R.id.description_title);
title.setText(items.get(i).getName());
// Выводим сообщение с текстом выбранного элемента
//Toast.makeText(getApplicationContext(), "Вы выбрали: " + Name, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView) findViewById(R.id.description_image);
image.setImageResource(items.get(i).getImageResourceId());
TextView description = (TextView) findViewById(R.id.description_text);
description.setText(items.get(i).getDescriptionText());
}
});
}
public void freshwaterInvertebratesClick(View view){
setContentView(R.layout.item_menu_list);
//Создание списка
final ArrayList<Item> items = new ArrayList<Item>();
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
items.add(new Item("Улиточка", R.mipmap.ic_launcher, "Маленькая красивая рыбка"));
items.add(new Item("Креветочка", R.drawable.ic_launcher_background, "рыбка чуть побольше"));
//Создание ссылки на{@link ItemAdapter}, который дает параметры создания листа
ItemAdapter adapter = new ItemAdapter(this, items, R.color.category_calc);
final ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// реализация кликабельности каждого элемента ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
setContentView(R.layout.description_window);
TextView title = (TextView) findViewById(R.id.description_title);
title.setText(items.get(i).getName());
// Выводим сообщение с текстом выбранного элемента
//Toast.makeText(getApplicationContext(), "Вы выбрали: " + Name, Toast.LENGTH_SHORT).show();
ImageView image = (ImageView) findViewById(R.id.description_image);
image.setImageResource(items.get(i).getImageResourceId());
TextView description = (TextView) findViewById(R.id.description_text);
description.setText(items.get(i).getDescriptionText());
}
});
}
}
package com.mogilevskiydenis.aquariumvici;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class Volume extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.volume);
}
public void calculate(View view) {
EditText length = (EditText) findViewById(R.id.length);
EditText width = (EditText) findViewById(R.id.width);
EditText height = (EditText) findViewById(R.id.height);
double a = 0, b = 0, c = 0;
if (length.getText().toString().equals("")) {
Toast.makeText(this, "Введите длину", Toast.LENGTH_SHORT).show();
}
else
{
a = Double.parseDouble(length.getText().toString());
}
if (width.getText().toString().equals("")) {
Toast.makeText(this, "Введите ширину", Toast.LENGTH_SHORT).show();
}
else
{
b = Double.parseDouble(width.getText().toString());
}
if (height.getText().toString().equals("")) {
Toast.makeText(this, "Введите высоту", Toast.LENGTH_SHORT).show();
}
else {
c = Double.parseDouble(height.getText().toString());
}
double volume = (a*b*c)/1000;
TextView answer = (TextView) findViewById(R.id.answer);
answer.setText(Double.toString(volume) + "л.");
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Длина в см"
android:textSize="25sp"/>
<EditText
android:id="@+id/length"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_gravity="center"
android:hint="Введите здесь длину"
android:gravity="center"
android:maxLines="1"
android:maxLength="20"
android:inputType="numberDecimal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ширина в см"
android:layout_gravity="center"
android:textSize="25sp"
/>
<EditText
android:id="@+id/width"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:hint="Введите здесь ширину"
android:maxLines="1"
android:maxLength="20"
android:inputType="numberDecimal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Высота в см"
android:layout_gravity="center"
android:textSize="25sp" />
<EditText
android:id="@+id/height"
android:layout_height="50dp"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:hint="Введите здесь высоту"
android:maxLines="1"
android:maxLength="20"
android:inputType="numberDecimal"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Рассчитать"
android:onClick="calculate"/>
<TextView
android:id="@+id/answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textSize="60sp"
android:textAllCaps="true"
android:textStyle="bold"
android:layout_gravity="center"
/>
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment