package com.example.mobapp_05;

import java.util.ArrayList;
import java.util.Arrays;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class MainActivity extends Activity {

	ArrayAdapter<String> adapter;
	ArrayList<String> entries;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		String[] data={"01", "02", "03", "04", "05", "06", "07","08","09","10","11","12" };
		
		// try this out
		//adapter = new ArrayAdapter<String>(this, 
		//        android.R.layout.simple_list_item_1, data);
		
		entries = 
		        new ArrayList<String>(Arrays.asList(data));

		adapter= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, entries);
				
		ListView listView = (ListView) findViewById(R.id.listView1);
		listView.setAdapter(adapter);
		
		listView.setOnItemClickListener(mMessageClickedHandler); 
	}

	public void click_add(View view)
	{
		EditText text = (EditText)findViewById(R.id.editText1);
		Editable s = text.getText();

		entries.add(0,s.toString());
		adapter.notifyDataSetChanged();
		
		
		
	}
	
	public void click_del(View view)
	{
		EditText text = (EditText)findViewById(R.id.editText1);
		Editable s = text.getText();
		
		ListView lv = (ListView)findViewById(R.id.listView1);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
	
	private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
	    public void onItemClick(AdapterView parent, View v, int position, long id) {
	        // Do something in response to the click
	    	EditText text = (EditText)findViewById(R.id.editText2);
	    	text.setText("idx "+(position+1));
	    	
	    	String s =  entries.get(position);
	    	s = s +"!";
	    	entries.set(position, s);
	    	adapter.notifyDataSetChanged();
	    	
	    }
	};
}
