elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Entrar al Canal Oficial Telegram de elhacker.net


  Mostrar Temas
Páginas: [1]
1  Programación / Java / Ayuda llamar a una clase y sus métodos dentro de otra clase (Android) en: 18 Abril 2015, 22:30 pm
Pues eso de toda la vida

Ipprivada test = new Ipprivada();
test.mimetodo();

El problema es que simplemente parece no funcionar en android, aviso que soy nuevo en android no seáis muy duros conmigo, aquí dejo las dos clases

Código:
package com.example.tab2;

import android.support.v7.app.ActionBarActivity;
import android.widget.TabHost;
import android.widget.TextView;
import android.content.Intent;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {

TextView texto;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Ipprivada test = new Ipprivada();





TabHost tabs=(TabHost)findViewById(android.R.id.tabhost);
tabs.setup();


TabHost.TabSpec spec=tabs.newTabSpec("mitab1");
test.Mostrar();
spec.setContent(R.id.tab1);
spec.setIndicator("TAB1");
   
tabs.addTab(spec);

spec=tabs.newTabSpec("mitab2");



spec.setContent(R.id.tab2);
spec.setIndicator("TAB2");
 
tabs.addTab(spec);

tabs.setCurrentTab(0);
}

}




Código:
package com.example.tab2;


import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;

public class Ipprivada extends ActionBarActivity {

TextView texto;


void Mostrar(){

texto = (TextView) findViewById(R.id.Ipprivada);
texto.setText("Hola");


}




}



El main xml:

Código:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent">
 
<TabHost android:id="@android:id/tabhost"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
     <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
 
         <TabWidget android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@android:id/tabs" />
 
         <FrameLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@android:id/tabcontent" >
 
            <LinearLayout android:id="@+id/tab1"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent" >
 
                <TextView android:id="@+id/Ipprivada"
                      android:text="Contenido Tab 1"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content" />
        </LinearLayout>
 
            <LinearLayout android:id="@+id/tab2"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent" >
 
                <TextView android:id="@+id/Ippublica"
                      android:text="Contenido Tab 2"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content" />
        </LinearLayout>
         </FrameLayout>
    </LinearLayout>
</TabHost>
</LinearLayout>



Igual es la cosa mas simple del mundo, pero lo he intentado todo, como veis esta todo en el mismo paquete, la verdad es que hay conceptos de programación de android que se me escapan bastante, nunca he trabajado con interfaces y son una locura, encima tampoco se si tengo que poner la clase en manifiesto.xml android pufff todo un lió la verdad, por cierto si creo un método con la función mostrar();dentro de la clase Main la aplicación funciona correctamente, intentando cargar la clase Ipprivada y luego llamando al método Mostrar la aplicación deja de funcionar.
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines