我正在尝试使用AutoCompleteTextView建议进行点击,并为用户带来另一项活动。如果你们中的任何人都知道如何使用AutoCompleteTextView,请前往AutoCompleteTextView or SearchDialog?
除了调用getText()之外,还有我正在使用的内容。另外如何在我的交换机案例中定义我的意图?
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)
{
final int autoComplete;
super.onCreate(savedInstanceSate);
setContentView(R.layout.searchshop);
AutoCompleteTextView autoCompletee = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, shops);
autoCompletee.setAdapter(adapter);
autoCompletee.setThreshold(1);
autoCompletee.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++)
{
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"
};
}
答案 0 :(得分:0)
我不知道你在int上调用getText()
的位置。要将int
转换为String
,您可以使用String.valueOf()
或Integer.toString()
。
你应该用另一种方式构建意图:
intent = new Intent(Search.this, YourAnotherActivityName.class);
补充阅读:
How to start activities
How to pass data between activities