package com.maxleap.starter;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class Main3Activity extends BaseActivity {
    private List<Fruit> fruitList = new ArrayList<Fruit>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        //设置一个最简单的ListView
        initFruits(); // 初始化水果数据
        FruitAdapter adapter = new FruitAdapter(Main3Activity.this,
                R.layout.list_item, fruitList);
        ListView listView = (ListView) findViewById(R.id.listview);
        listView.setAdapter(adapter);
        //设置ListView项目点击事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Fruit fruit = fruitList.get(position);
                Toast.makeText(Main3Activity.this, fruit.getName(),
                        Toast.LENGTH_SHORT).show();
            }
        });





        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Metro Map", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                Intent intent=new Intent(Main3Activity.this,Main4Activity.class);
                startActivity(intent);
            }
        });
    }

    private void initFruits() {
        Fruit apple = new Fruit("Apple", R.mipmap.n);
        fruitList.add(apple);
        Fruit banana = new Fruit("Banana", R.mipmap.n);
        fruitList.add(banana);
        Fruit orange = new Fruit("Orange", R.mipmap.n);
        fruitList.add(orange);
        Fruit watermelon = new Fruit("Watermelon", R.mipmap.n);
        fruitList.add(watermelon);
        Fruit pear = new Fruit("Pear", R.mipmap.n);
        fruitList.add(pear);
        Fruit grape = new Fruit("Grape", R.mipmap.n);
        fruitList.add(grape);
        Fruit pineapple = new Fruit("Pineapple", R.mipmap.n);
        fruitList.add(pineapple);
        Fruit strawberry = new Fruit("Strawberry", R.mipmap.n);
        fruitList.add(strawberry);
        Fruit cherry = new Fruit("Cherry", R.mipmap.n);
        fruitList.add(cherry);
        Fruit mango = new Fruit("Mango", R.mipmap.n);
        fruitList.add(mango);
    }

}
