vtking vtking - 4 months ago 34
Android Question

how to override getView() method in activity extend Listactivity

My project have a listview and MainActivity extend ListActivity, so I work "Alt+Shift+S" to add method getView() but I can not find getView() in this list.

Please show me, I need call getView() method.
Thank you!

Answer

getView() is a method of List adapter. So to Override it you need to set a custom adapter to your activity ref: http://www.vogella.com/tutorials/AndroidListView/article.html

public class MySimpleArrayAdapter extends ArrayAdapter<String> {
  public MySimpleArrayAdapter(Context context, String[] values) {
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    return rowView;
  }
}

in your Activity:

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
        MySimpleArrayAdapter<String> adapter = new MySimpleArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, values);
    setListAdapter(adapter);
  }