어떻게 autoComplete를 초기화합니까? AutoCompleteTextView와 함께 사용할 수는 없기 때문에 로컬 변수가 중복되었음을 알 수 있습니다. 그것을 정적으로 선언하려고 시도했지만 허용되지 않습니다.로컬 변수가 초기화되지 않았을 수 있습니다.
제발 상담하십시오!
public class Search extends Activity {
public void onCreate(Bundle savedInstanceSate) {
final int autoComplete;
super.onCreate(savedInstanceSate);
setContentView(R.layout.searchshop);
//The duplicate im talking about
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++) {
//The local variable autoComplete may not been initialized
if(shops[i].equals(Integer.toString(autoComplete))) {
index=i;
break;
}
}
switch(index) {
case 0:
intent=new Intent(Search.this, Adidas.class);
startActivity(intent);
break;
case 1:
intent=new Intent(Search.this, Affin.class);
startActivity(intent);
break;
}
}
});
}
static final String[] shops = new String[] {
"Adidas", "Affin Bank", "Alam Art", "Al Amin"
};
}
이것은 의미가 없습니다. autoComplete라는 어떤 변수도 할당되지 않은 변수가 있습니다. 물론 초기화되지 않았습니다. 질문이 뭐야? –
답변은 'autoComplete'에 어떤 가치가 있는지에 달려 있습니다. – dasblinkenlight
질문은 방법, 그러나 왜 그렇게 많은 것이 아닙니다. 내가 볼 수있는 한, 항상 false를 반환하는 하나의'equals' 호출을 제외하고 변수는 사용되지 않습니다. – biziclop