ListActivity

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

ListActivity

Postby rohan » Thu Jul 16, 2009 9:03 am

Hi all,
In this code i am facing problem to setSelection the list item at position 1. So when the activity starts up i need to get the focus of the list item at position 1.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class GroupList extends ListActivity {
  2.  
  3.                                    public static List<String> groupName = new ArrayList<String>();
  4.  
  5.                                           public void onCreate(Bundle savedInstanceState) {
  6.  
  7.                                                  super.onCreate(savedInstanceState);
  8.  
  9.                                                   ArrayAdapter <String> fileList = new ArrayAdapter<String>    (this,R.layout.grouplist,groupName);      
  10.  
  11.                                               setListAdapter(fileList);      
  12.  
  13.                                                }
  14.  
  15.                              public void onStart() {
  16.  
  17.                                         super.onStart();
  18.  
  19.                                          this.setSelection(1); //Problem....
  20.  
  21.                                 }
  22.  
  23.               }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


Thanks in advance.....
rohan
Developer
Developer
 
Posts: 34
Joined: Wed Mar 19, 2008 2:26 pm

Top

Postby nmc » Thu Jul 16, 2009 10:03 am

Just a quick guess: no items in your list? 8)
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby rohan » Thu Jul 16, 2009 10:21 am

Hi thanks for the reply...

In my other class as the variable is static i am adding elements into the list. And after adding items in this list i am
starting this activity.. So items are there in the list....

Thanks in advance...
rohan
Developer
Developer
 
Posts: 34
Joined: Wed Mar 19, 2008 2:26 pm

Postby rohan » Thu Jul 16, 2009 10:45 am

HI,

I am able to setselection through the following...
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  public boolean onPrepareOptionsMenu(Menu menu)
  2.  
  3.           {
  4.  
  5.        
  6.  
  7.         this.setSelection(1);
  8.  
  9.        
  10.  
  11.         return true;
  12.  
  13.           }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


While i press menu it is able to get the focus to the second item of the list....

Thanks in advance...
rohan
Developer
Developer
 
Posts: 34
Joined: Wed Mar 19, 2008 2:26 pm

Postby nmc » Thu Jul 16, 2009 10:49 am

What happens when you move the trackball up/down after the list opens? Maybe you just cant see the selection because the list doesnt have the focus?
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby rohan » Thu Jul 16, 2009 11:07 am

Hi nmc ... thanks for the reply..

I have around 8 items in my list.. When the activity starts the list does not have focus. When i press down key twice then the focus comes to the first item on the list.. An activity is called when an item on the list is clicked and when "back" button is pressed on the same activity, focus should be on the same item that was selected...


Thanks in advance...
rohan
Developer
Developer
 
Posts: 34
Joined: Wed Mar 19, 2008 2:26 pm

Top

Postby nmc » Thu Jul 16, 2009 11:53 am

Looks like onStart() is called too early then.
Maybe try onResume() instead?
Try requestFocus() befor setSelection()?
nmc
Senior Developer
Senior Developer
 
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby rohan » Fri Jul 17, 2009 7:07 am

Hi,
I tried with onResume() .. but it did not work... When i tried with onPrepareOptionsMenu it worked...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public boolean onPrepareOptionsMenu(Menu menu)
  2.  
  3.           {
  4.  
  5.        
  6.  
  7.         this.setSelection(1);
  8.  
  9.        
  10.  
  11.         return true;
  12.  
  13.           }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


How do i get focus on an item of List...

Thanks....
rohan
Developer
Developer
 
Posts: 34
Joined: Wed Mar 19, 2008 2:26 pm

Top

Return to General

Who is online

Users browsing this forum: Google Feedfetcher and 5 guests