connect XML to java?

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

connect XML to java?

Postby Ansem » Sat Mar 10, 2012 11:32 am

Hi, i create an object that open a link in the broswer when i tap on the button.
The problem is that when i tap on the button on the emulator nothing append :(
For the problem is that i don't use the right name for the object :/
this is the XML code:
Code: Select all
<Button
        android:id="@+id/btnRegistrazione"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/Registrati" />


and this is the java code:
Code: Select all
public class EasyParkingActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public class Registrazione extends Activity implements View.OnClickListener{
            private Button btnRegistrazione;
             
            @Override
            public void onCreate(Bundle b){
            super.onCreate(b);
             
            btnRegistrazione = new Button(this);
            btnRegistrazione.setOnClickListener(this);
             
            aprilink("http://www.google.it");
             
            setContentView(btnRegistrazione);
            }
             
            public void onClick(View v){
            aprilink("http://www.google.it");
            }
           
            private void aprilink( String string ){
                    Intent browse = new Intent( Intent.ACTION_VIEW, Uri.parse(string) );

                startActivity( browse );
                }
            };
Ansem
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 08, 2012 4:23 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 3 guests