Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing ListView : How to add a header view?
    primarykey
    data
    text
    <p>I looke at <a href="http://developer.android.com/reference/android/widget/ListView.html">the ListView API</a> and I saw the method: </p> <blockquote> <p>addHeaderView(View v)</p> </blockquote> <p>What I want to do is to have a layout above the list, is this possible ?</p> <p>I tried doing something like :</p> <pre><code> EditText et=new EditText(this); et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); et.setInputType(InputType.TYPE_CLASS_TEXT); addHeaderView(et); //makes app crash </code></pre> <p>I also tried </p> <pre><code>setContentView(R.layout.tryview); </code></pre> <p>but it also make the app crash.</p> <p>Help is very much appreciated!</p> <p><strong>Edit</strong> : The code for this class is:</p> <pre><code>public class GroupsActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String your_array_contents[] = {"a","ab","c"}; setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.groups_layout, your_array_contents)); EditText et=new EditText(this); et.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); et.setInputType(InputType.TYPE_CLASS_TEXT); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); lv.setAdapter(new ArrayAdapter&lt;String&gt;(GroupsActivity.this, android.R.layout.simple_list_item_multiple_choice, your_array_contents)); lv.addHeaderView(et); //makes app crash lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // When clicked, show a toast with the TextView text // Toast.makeText(getApplicationContext(), ((TextView) view).getText(), //Toast.LENGTH_SHORT).show(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload