package com.example.ghomi.chapter4_1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    ListView lw;
    private String[] fruitArray ;
    private ArrayAdapter arrayAdapter;
    TextView tv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
                lw = (ListView) findViewById(R.id.listView);
                tv = (TextView)findViewById(R.id.textView);
                fruitArray = new String[5];
                fruitArray[0] = "Orange";
                fruitArray[1] = "Apple";
                fruitArray[2] = "Mango";
                fruitArray[3] = "Lemon";
                fruitArray[4] = "Banana";
                arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, fruitArray);
                lw.setAdapter(arrayAdapter);
                lw.setOnItemClickListener(new OnItemClickListener() {
       public void onItemClick (AdapterView<?> parent, View v, int position, long id) {
                           // Your code here
                            String item = ((TextView)v).getText().toString();
                            tv.setText("Your select : " + item);
                          }
       });
    }
}
