2013-04-24 67 views
1

我有以下代码,并且我试图链接String [] teamsteam1Input字段。该程序目前崩溃,我相当肯定我没有正确使用team1Input.getId()。我怎样才能做到这一点,而不触摸任何XML?AutocompleteTextView和ArrayAdapter以编程方式崩溃

final AutoCompleteTextView team1Input = new AutoCompleteTextView(this); 
     team1Input.setLayoutParams(new LinearLayout.LayoutParams(
       LinearLayout.LayoutParams.MATCH_PARENT, 
       LinearLayout.LayoutParams.WRAP_CONTENT 
       )); 
     ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, team1Input.getId(), teams); 
     team1Input.setAdapter(adapter); 
     row1.addView(team1Input); 

回答

0

作为docs状态:

textViewResourceId用于容纳一个TextView实例视图时使用的布局文件中的资源ID。

你不应该传递TextView的id。预计的ID是一个R.layout.your_layout_here。这个布局文件必须只有一个TextView。

+0

如果我不想使用XML来定义此AlertDialog的布局,该怎么办? R.id.xxx只适用于XML的东西吗? – MasterGberry 2013-04-24 21:40:59

+0

然后考虑传递0作为id并实现您自己的自定义适配器。你会在Google上找到很多教程。 – 2013-04-24 21:43:05

+0

此解答是否有用?你有没有设法解决你的问题? – 2013-04-26 13:38:25

相关问题