0

I want to fill the first listview line with an int from another method in my databasehelper, and the fill the rest of the view.

All I can find googleing this is how to do it with an ArrayAdapter

this is how i fill the view now:

        new Handler().post(new Runnable(){          
        @Override
        public void run(){
            cursorAdapter = new CustomCursorAdapter(MainActivity.this, contactDBHelper.listAll());

            listView.setAdapter(cursorAdapter);
        }

    });

what I want to do is to fill the first line with the coming int from this method.

contactDBHelper.countContact();

Any ideas?

The Dude
  • 1,088
  • 7
  • 16
  • 30
  • 1
    Why not use a header view on your list for that? http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View) – ebarrenechea Oct 25 '14 at 17:45
  • Been looking on that, but cant seem to grasp how it works – The Dude Oct 25 '14 at 17:47
  • It works just like any other view on your layout. Just add a new `TextView` to your layout xml file, find it after inflating or setting the content view, set its text to the result of `countContact()` and add it as a header for your list. Here's a link to a good tutorial: http://www.vogella.com/tutorials/AndroidListView/article.html#miscellaneous_headerfooter – ebarrenechea Oct 25 '14 at 17:53
  • create a TextView set text countContact and add it as header view to list view as `listview.addHeaderView(view);` – Rustam Oct 25 '14 at 17:57
  • listView.addHeaderView is not allowd – The Dude Oct 25 '14 at 18:42

2 Answers2

0

try using ListVew.addHeaderView(View view)

    ListView lv=(ListView) findViewById(R.id.listView1);
    TextView header=new TextView(getApplicationContext());
    header.setText("Header");
    lv.addHeaderView(header);
fatboy
  • 2,107
  • 1
  • 12
  • 13
0

You can override getItemViewType and getViewTypeCount methods if you want to display different views at the ListView. Here is a short example.

Community
  • 1
  • 1
nikis
  • 11,166
  • 2
  • 35
  • 45