0
votes

I am creating a list view with header. I have created header.xml in which I have an image. But when I scroll the list header also scrolls. It should be always at the top.`public class CustomListActivity extends ListActivity {

    static final String[] Actress = 
               //new String[] { "Katrina Kaif", "Aishwarya", "Genelia", "Vidya", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid"};
    new String[] { "Aishwarya", "Genelia","Katrina Kaif",   "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Khalid", "Vidya",};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ListView lv = getListView();
        View header = getLayoutInflater().inflate(R.layout.header, null);
        lv.addHeaderView(header);
        setListAdapter(new MobileArrayAdapter(getApplicationContext(), Actress));


        lv.setTextFilterEnabled(true);


    }

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

        //get selected items
        String selectedValue = (String) getListAdapter().getItem(position);
        Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();

    }

}`
4
Then why don't you put TextView above ListView and set Title in it?Paresh Mayani

4 Answers

2
votes

Just place a view above your listview, no need to work with headers?

1
votes

Instead of putting the header as another cell, create a custom component. Something like (grosso modo):

<LinearLayout orientation="vertical">
  <Header/>
  <ScrollablePanel>
    <ListView/>
  </ScrollablePanel>
</LinearLayout>
0
votes

If you simply put whatever views you have in header.xml on top of the ListView in your ListActivity layout file it shouldn't scroll

0
votes

Try this:

LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);