package gr.mybook.mylistviews;


import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MyListActivity extends ListActivity {
	String[] items;
	ListView lView;
	String selectedValue;
	
	ArrayAdapter<String> mListAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
        lView = getListView();
        lView.setChoiceMode(2); 
        lView.setTextFilterEnabled(true);
        items = getResources().getStringArray(R.array.items1);
        //setListAdapter(new ArrayAdapter<String>(this,
        //         android.R.layout.simple_list_item_multiple_choice, items));
         mListAdapter = 
        	    new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, items);
         setListAdapter(mListAdapter);
     }
    
       public void onListItemClick(ListView lv, View v, int position, long id) {
    	   lv.setItemChecked(position, lv.isItemChecked(position));
    	   String selectedValue = (String) getListAdapter().getItem(position);
    	   lView.clearTextFilter();
    	   lView = getListView();
    	   items = getResources().getStringArray(R.array.items1);
    	   mListAdapter = 
           	    new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, items);
    	   setListAdapter(mListAdapter);
           
           for (int pos=0; pos<lView.getCount(); pos++) {
    		   String sValue = lView.getItemAtPosition(pos).toString();
    		   if (selectedValue.equals(sValue)){
    			 //  Toast.makeText(this, "pos="+pos, Toast.LENGTH_SHORT).show();
    			   lView.setItemChecked(pos, true);
    			   break;
    		   }
           }
           
           lView.setTextFilterEnabled(true);
     	   
/*         Intent intent = new Intent(this, Activity2.class);
           intent.putExtra("key", selectedValue);
           startActivity(intent);*/
           
       }
  }
