2011-06-15 19 views
7

¿Cómo puedo implementar esta funcionalidad?¿Cómo puedo acceder a los valores almacenados de un Bean desde otra Clase

ApplicationConstants.phoneContacts.add(
    new ContactNumberBean(nameOfContact, 
    contactNumber, contactNumberType)); 

ApplicationConstants y clases ContactNumberBean

ContactNumberBean:

package com.example.AddressBook; 

public class ContactNumberBean 
{ 
    private String nameOfContact; 
    private String contactNumber; 
    private int contactNumberType; 

    public String getnameOfContact() 
    { 
     return nameOfContact; 
    } 
    public String getcontactNumber() 
    { 
     return contactNumber; 
    } 
    public int getcontactNumberType() 
    { 
     return contactNumberType; 
    } 
    public ContactNumberBean(String nameOfContact, String contactNumber,int contactNumberType) 
    { 
     this.nameOfContact=nameOfContact; 
     this.contactNumber=contactNumber; 
     this.contactNumberType=contactNumberType; 

    } 
} 

ApplicationConstants:

package com.example.AddressBook; 

import java.util.ArrayList; 

public class ApplicationConstants 
{ 
    //String[] phoneContacts =new String[10]; 
    //ArrayList<NameValuePair> list = new ArrayList<NameValuePair>(); 

    /*String s1,s2; 
    int i1; 

    ContactNumberBean cb =new ContactNumberBean(str1,str2,i2); 

    static ArrayList<String> phoneContacts = new ArrayList<String>(); 
    phoneContacts.add(s1); 
    phoneContacts.add(s2); 
    phoneContacts.add(i1);*/ 

how can implemented in this class functionality ................................ 

**ApplicationConstants.phoneContacts.add(new ContactNumberBean(nameOfContact, 
             contactNumber, contactNumberType));** 


} 

por favor envíe un poco de solución gracias de antemano .... Narasimha

+0

¿Podría alguien de los votantes mayores editar esto? El primer párrafo no es muy claro. ¿Es esto algún tipo de inglés? – ernazm

Respuesta

1

hi acceder a los valores de estado en otra clase crear una clase común nombrado como Constants.java en que declarar e inicializar sido objeto, como a continuación:

public class Constants{ 

    public static Bean userBeen=new Bean(); 

} 

sido de clase:

public class Been { 

    private string countryName; 

    public void setCountry(String s) { 
     this.countryName=s; 
    } 

    public String getCountry() { 
     return countryName; 
    } 
} 

valores establecidos:

public class A{ 

    String s="India"; 

    Constants.userBeen.setCountry(s); 

    } 
} 

valores obtenemos:

public class B{ 

    String s=Constants.userBeen.getCountry(); 

    } 

} 

esto funcionará bien.

Cuestiones relacionadas