ListActivity does not work Android

0

I have an Activity with a button calling a List Activity. This ListActivity quickly creates a string list, I just want to show this list on the screen and display the selected item in a Toast.

But it's not working! Here is the code for the List class

public class Lista extends ListActivity{

    protected void OnCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        String[] itens = new String[]{"João","josé","pedro",};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,itens);
    setListAdapter(adapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

        Object o = this.getListAdapter().getItem(position);
        String item = o.toString();
        Toast.makeText(this, "Clicou em: "+item, Toast.LENGTH_SHORT).show();
    }

}

What's missing?

    
asked by anonymous 03.05.2014 / 03:01

1 answer

4

The Java code is case-sensitive , this means that Double is different from double , String is different string , and so on. p>

So you have an error in your code since the OnCreate method does not exist in the class ListActivity (and in turn, in Activity ) that was inherited and it happens that it never is run in its class. So you just need to change the spelling error to onCreate in the method signature:

protected void onCreate(Bundle savedInstanceState)

It's always good to use the @Override annotation, so it ensures that the method you're trying to redefine actually exists in the super class.

    
03.05.2014 / 12:21