views:

324

answers:

2

Hello All,

I have successfully implemented my AutoCompleteTextView which is based off an sqlite query and placed in an array adapter. Thats all working beautifully, however I cant et my onclickevent working. I just want to create an intent to pass the selected value to a new activity. I know how to create an onclicklistener I am just unsure about how to apply it to the dropdown box of the AutoCompleteTextView.

So far I've come up empty so any help is much appreciated!

Cheers

A: 

putExtra function can be used for this purpose. Can't it?

Here is an example...

Form the sending activity

lv.setOnItemClickListener(new OnItemClickListener()
    {  
        public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
            ApplicationInfo x = appinstalled.get(pos);
            PackageInfo y = appinstall.get(pos);
            //Intent i = new Intent(InstalledPackages.this, Information.class);
            i= new Intent(InstalledPackages.this, Information.class);
            i.putExtra("i",x);
            i.putExtra("j", y);
            startActivity(i);
    }
    });
}

on the recieving side

    super.onCreate(savedInstanceState);
    Intent myIntent = getIntent();
    ApplicationInfo i = (ApplicationInfo)myIntent.getParcelableExtra("i");
    PackageInfo j = (PackageInfo)myIntent.getParcelableExtra("j");
Shouvik
Ally
A: 

Nevermind I've solved it I was just executing poorly. The code below autocompletes my textview based off a simple SELECT sqlite statement & executes when the user selects the uni from the dropdown list. The onclick event creates a new intent and starts a new activity passing the selection to this activity within the intent.

    final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.ac_university);
String[] universities = myDbHelper.getAllUnis(db);

// Print out the values to the log
for(int i = 0; i < universities.length; i++)
 {
    Log.i(this.toString(), universities[i]);
}        

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, universities);
textView.setAdapter(adapter);
//textView.setOnItemSelectedListener(this);
textView.setOnItemClickListener(new OnItemClickListener() { 

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {

        Intent intent = new Intent(Main.this, Campus.class);
        Bundle bundle = new Bundle();

        bundle.putString("university_name", arg0.getItemAtPosition(arg2).toString());
        bundle.putLong("_id", arg3);
        intent.putExtras(bundle);
        startActivity(intent); 

    }
Ally