我的活动类中定义了一些公共变量:
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");
如您所见,这些变量从某些活动中获取其值。
如何在单独的类中访问这些变量?
我的单独课程:
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;
}
});
}
在本课程中,我必须将这些变量分配给:
query.whereEqualTo("Type","");
我该怎么做?
谢谢和问候
答案 0 :(得分:0)
将其声明为static
public static String typeQuery;
现在您可以在其他课程中使用它们
RentListingFeed.typeQuery
答案 1 :(得分:0)
您不应将类变量声明为public。正确的方法是将它们设为私有,并通过各自的方法获取/设置它们。对于类型,它应该是这样的:
public void setTypeQuery(String typeQuery) {
this.typeQuery = typeQuery;
}
public String getTypeQuery() {
return this.typeQuery;
}
现在,您可以在CustomAdapter中创建类的对象,并根据需要设置/获取这些变量:
RentListingFeed rentListingFeed = new RentListingFeed();
rentListingFeed.getTypeQuery();