How to make the second button to be focused?

Put your problem here if it does not fit any of the other categories.

How to make the second button to be focused?

Postby flydream » Fri Mar 07, 2008 1:23 pm

In the Android example, ApiDemos, there is a activity: Focus2,

code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.google.android.samples.view;
  2.  
  3.  
  4.  
  5. import com.google.android.samples.R;
  6.  
  7.  
  8.  
  9. import android.app.Activity;
  10.  
  11. import android.os.Bundle;
  12.  
  13.  
  14.  
  15. public class Focus2 extends Activity {
  16.  
  17.  
  18.  
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.  
  21.         super.onCreate(savedInstanceState);
  22.  
  23.  
  24.  
  25.         setContentView(R.layout.focus_2);
  26.  
  27.     }
  28.  
  29. }
  30.  
  31.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

xml:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.    android:layout_height="wrap_content"
  4.  
  5.    android:layout_width="fill_parent"
  6.  
  7.    android:orientation="horizontal">
  8.  
  9.  
  10.  
  11.     <Button android:id="@+id/leftButton"
  12.  
  13.        android:layout_width="wrap_content"
  14.  
  15.        android:layout_height="wrap_content"
  16.  
  17.        android:layout_marginRight="3dip"
  18.  
  19.        android:text="@string/focus_2_left"
  20.  
  21.        android:nextFocusRight="@+id/rightButton"/>  <!-- jump over middle! -->
  22.  
  23.  
  24.  
  25.     <Button android:id="@+id/centerButton"
  26.  
  27.        android:layout_width="wrap_content"
  28.  
  29.        android:layout_height="wrap_content"
  30.  
  31.        android:layout_marginRight="3dip"
  32.  
  33.        android:text="@string/focus_2_jump" />
  34.  
  35.  
  36.  
  37.     <Button android:id="@+id/rightButton"
  38.  
  39.        android:layout_width="wrap_content"
  40.  
  41.        android:layout_height="wrap_content"
  42.  
  43.        android:layout_marginRight="3dip"
  44.  
  45.        android:text="@string/focus_2_right"/>
  46.  
  47.    
  48.  
  49. </LinearLayout>
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


when first enter this activity, and press any key, then the first button is focused.
My questions is: how to change the code, let the second button to be focused when I first press any navigate key. I try requestFocus(), but failed.
flydream
Freshman
Freshman
 
Posts: 2
Joined: Thu Feb 21, 2008 8:14 am

Top

Postby plusminus » Fri Mar 07, 2008 4:31 pm

Hello flydream,

lets say, requestFocus() should be working. (Did you als try to write [font=Lucida Console]<requestFocus/>[/font] to xml ?)

Focus-stuff seems to be currently a bit buggy: http://www.anddev.org/viewtopic.php?t=1110

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby flydream » Mon Mar 10, 2008 3:52 am

Yes. I have tried these two method to set the default focus.
one is set attribute in xml:
<Button android:id="@+id/centerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dip"
android:text="@string/focus_2_jump"
android:focusableInTouchMode="true">
<requestFocus/>
</Button>

the other is in code:
setContentView(R.layout.focus_2);
findViewById(R.id.centerButton).requestFocus();

But these two method have no effects on the default focus.
flydream
Freshman
Freshman
 
Posts: 2
Joined: Thu Feb 21, 2008 8:14 am

Postby plusminus » Mon Mar 10, 2008 3:11 pm

Hello flydream

I could swear this was working in m3... lets hope it shows correct behavior in the next sdk-releases.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 16 guests