KenDiriwan
Lurker
I want user to just select an item from AutoCompleteTextView and once he selects it,it should bring you to another .xml that i have already created.
Below are my source and the error i marked with //
Below are my source and the error i marked with //
Code:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class Search extends Activity
{
public void onCreate(Bundle savedInstanceSate)
{
super.onCreate(savedInstanceSate);
setContentView(R.layout.searchshop);
AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, shops);
autoComplete.setAdapter(adapter);
autoComplete.setThreshold(1);
autoComplete.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Intent intent;
int index=999;
for(int i=0;i<shops.length;i++)
{
//Cannot refer to a non-final variable autoComplete inside an inner class defined in a different method
if(shops[i].equals(autoComplete.getText().toString().trim()))
{
index=i;
break;
}
}
switch(index)
{
case 0:
//The constructor Intent(Search, int) is undefined
intent=new Intent(Search.this, R.layout.adidas);
startActivity(intent);
setContentView(R.layout.adidas);
break;
case 1:
//The constructor Intent(Search, int) is undefined
intent=new Intent(Search.this, R.layout.affin);
startActivity(intent);
setContentView(R.layout.affin);
break;
}
}
});
}
static final String[] shops = new String[]
{
"Adidas", " Affin Bank", "Alam Art", "Al Amin"
};
}