package com.example.patrice.http01;


import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
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;

//https://android--code.blogspot.fr/2015/08/android-listview-scroll-to-item.html

public class listview03 extends AppCompatActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview03_layout);

        arrayAdapterListView();
    }


    private void arrayAdapterListView()
    {
        setTitle("dev2qa.com - ArrayAdapter List View Example");

        List<String> dataList = new ArrayList<String>();
        dataList.add("Java");
        dataList.add("Android");
        dataList.add("JavaEE");
        dataList.add("JSP");
        dataList.add("JDBC");

        ListView listView = (ListView)findViewById(R.id.listViewExample);

        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, dataList);
        listView.setAdapter(arrayAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int index, long l)
            {
                Object clickItemObj = adapterView.getAdapter().getItem(index);
                Toast.makeText(listview03.this, "You clicked " + clickItemObj.toString(), Toast.LENGTH_SHORT).show();
            }
        });
    }
}