嗨,我是Android新手。誰能告訴我請什麼錯用下面的代碼:以編程方式創建ListView
public class ListApp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView lText = new TextView(this);
lText.setId(0);
ListView lView = new ListView(this);
String[] lStr = new String[]{"AA","BB", "CC"};
ArrayAdapter lAdap = new ArrayAdapter(this,lText.getId(),lStr);
lView.setAdapter(lAdap);
lView.setFocusableInTouchMode(true);
setContentView(lView);
}
}
一方面,您錯誤地使用了ArrayAdapter構造函數。你想使用兩個參數版本:(Context context,int textViewResourceId) – moonlightcheese 2011-05-27 19:35:42
像這樣:ArrayAdapter lAdap = new ArrayAdapter (this,lText.getId()); –
moonlightcheese
2011-05-27 19:38:47