Create ListView programmatically

Viewed 39620

Hi I am new in Android. Could anyone tell me pls whats the wrong with the following code:

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);
    }
}
5 Answers
Related