Expanding a list view


Last Updated:

  1. bscarl88

    bscarl88 Member This Topic's Starter

    Joined:
    Jul 2, 2010
    Messages:
    8
    Likes Received:
    1
    I have a tabhost layout with a list in each tab. I am trying to make a listview in a listview like the default music player on the droid, or when clicking on a listview bring up a menu with a list of options (about 7) to choose from. I'm really trying for the former but I can't find anyway to do it, I've tried onListItemClick going to another activity where I will define another list, but it won't work because of errors that I cannot seem to fix to get it working properly.

    Code (Text):
    1.     @Override
    2.     public void onCreate(Bundle savedInstanceState)
    3.     {
    4.       final String[] CDExplorer_tabs = new String[] {"item1", "item2", "item3", "item4", "item5"};
    5.       super.onCreate(savedInstanceState);
    6.  
    7.       setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, CDExplorer_tabs));
    8.  
    9.       ListView lv = getListView();
    10.       lv.setTextFilterEnabled(true);
    11.       registerForContextMenu(lv);
    12.       public void onListItemClick( ListView parent, View v, int position, long id)
    13.       {
    14.           final Intent i = new Intent(this, CDETabs.class);
    15.           startActivity(i);
    16.       }
    17.  
    18.     }
    19. }
    any ideas?
     

    Advertisement
  2. Boogs

    Boogs Well-Known Member

    Joined:
    Apr 6, 2010
    Messages:
    85
    Likes Received:
    16
    I'd say, first things first, take your onListItemClick method out of your onCreate method to override the method in your ListActivity class.
     
    bscarl88 likes this.
  3. bscarl88

    bscarl88 Member This Topic's Starter

    Joined:
    Jul 2, 2010
    Messages:
    8
    Likes Received:
    1
    That helped me fix the errors! thanks! Now I can't find any tutorials on it so I have a couple more questions sadly. Is there any info on how to open the new list under its appropriate list item (like the droid music player)? Should I create a new list_item layout to reference for the new list? And do I have to create a new class for each item in the new list in a new java file?

    Code (Text):
    1.  
    2. public class AlbumTab extends ListActivity
    3. {
    4.     @Override
    5.     public void onCreate(Bundle savedInstanceState)
    6.     {
    7.       final String[] CDExplorer_tabs = new String[] {"item1", "item2", "item3", "item4"};
    8.       super.onCreate(savedInstanceState);
    9.  
    10.       setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, CDExplorer_tabs));
    11.  
    12.       ListView lv = getListView();
    13.       lv.setTextFilterEnabled(true);
    14.       registerForContextMenu(lv);
    15.     }
    16.     @Override
    17.     public void onListItemClick(ListView lv, View v, int position, long id)
    18.     {
    19.       final Intent i = new Intent(this, CDETabs.class);
    20.       startActivity(i);
    21.     }
    22. }
    23.  
    24.  
    here is the current list_layout that it references

    HTML:
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <TextView
    4.        
    5.         xmlns:android="http://schemas.android.com/apk/res/android"
    6.         android:layout_width="fill_parent"
    7.         android:layout_height="fill_parent"
    8.         android:padding="10dp"
    9.         android:textSize="16sp" >
    10. </TextView>
    11.  
    12.  
     
  4. bscarl88

    bscarl88 Member This Topic's Starter

    Joined:
    Jul 2, 2010
    Messages:
    8
    Likes Received:
    1
    Nevermind, I ended up making a list appear in a whole new window which works just as fine.
     

Share This Page

Loading...