Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

java - How to access public variables declared in an Activity class from another class in android

I have some public variables define in my activity class:

public class RentListingFeed extends ActionBarActivity {

    private ParseQueryAdapter<ParseObject> mainAdapter;
    private CustomAdapter rexovoAdapter;
    private ListView listView;

    public String typeQuery;
    public String bedQuery;
    public String toiletQuery;
    public String condQuery;
    public String availQuery;
    public String intentionQuery;

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


        typeQuery=getIntent().getStringExtra("Type");
        bedQuery=getIntent().getStringExtra("Beds");
        toiletQuery=getIntent().getStringExtra("Toilets");
        condQuery=getIntent().getStringExtra("Condition");
        availQuery=getIntent().getStringExtra("Availability");
        intentionQuery=getIntent().getStringExtra("Intention");

As you can see, these variable are getting their values from some activity.

How can I access these variable in a separate class?

My separate class:

public class CustomAdapter extends ParseQueryAdapter<ParseObject> {

    public CustomAdapter(Context context) {
        // Use the QueryFactory to construct a PQA that will only show
        // Todos marked as high-pri
        super(context, new QueryFactory<ParseObject>() {
            public ParseQuery create() {
                ParseQuery query = new ParseQuery("PropertyDetails");
                query.whereEqualTo("Tag", "Property");
                query.whereEqualTo("Type","");
                return query;
            }
        });
    }

In this class, I have to assign these variables to :

query.whereEqualTo("Type","");

How can I do that?

Thanks and Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Declare them as static

public static String typeQuery;

Now you can use them in your other class

RentListingFeed.typeQuery

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...