我获得了select方法中定义的selectedCategoryId的值,在另一个方法initCat中,获取了selectedCategoryId的0值,有没有办法从一个方法获取值到同一个类中的另一个方法,帮我解决
这是我的代码
package com.panaceasoft.myPack.fragments;
public class BusinessRegisterFragment extends Fragment implements View.OnClickListener {
private ArrayList < PCityData > cityArrayList;
private ArrayList < PSubCategoryData > subCatArrayList;
private ArrayList < PCityData > cityDataSet;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_business_register, container, false);
initData();
initUI();
initCat();
return view;
}
private void initData() {}
public void initUI() {
cityPopupContainer = (LinearLayout) view.findViewById(R.id.choose_city_container);
cityPopupContainer.removeAllViews();
catPopupContainer = (LinearLayout) view.findViewById(R.id.choose_cat_container);
catPopupContainer.removeAllViews();
subCatPopupContainer = (LinearLayout) view.findViewById(R.id.choose_sub_cat_container);
subCatPopupContainer.removeAllViews();
PPopupSingleSelectView pPopupSingleSelectView = new PPopupSingleSelectView(getActivity(), selectCategoryString, GlobalData.categoryDatas, "");
pPopupSingleSelectView.setOnSelectListener(new SelectListener() {
@Override
public void Select(View view, int position, CharSequence text) {}
@Override
public void Select(View view, int position, CharSequence text, int id) {
selectedCategoryId = id;
selectedCategoryName = text.toString();
}
@Override
public void Select(View view, int position, CharSequence text, int id, float additionalPrice) {}
});
catPopupContainer.addView(pPopupSingleSelectView);
imageToUplaod.setOnClickListener(this);
bUploadImage.setOnClickListener(this);
bSelectImage.setOnClickListener(this);
btnRegisterBusiness.setOnClickListener(new View.OnClickListener() {@
Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
doRegister();
}
});
btnCancelBusiness.setOnClickListener(new View.OnClickListener() {@
Override
public void onClick(View v) {
doCancel();
}
});
prgDialog = new ProgressDialog(getActivity());
prgDialog.setMessage("Please wait...");
prgDialog.setCancelable(false);
}
private void initCat() {
requestSubCategory(Config.APP_API + Config.GET_SUBCAT_BY_CAT + "?cat_id=" + selectedCategoryId);
}
}
答案 0 :(得分:0)
试试这个
private void initCat(int catID) {
requestSubCategory(Config.APP_API + Config.GET_SUBCAT_BY_CAT +"?cat_id="+catID);
}
并从select()
方法调用。
@Override
public void Select(View view, int position, CharSequence text, int id) {
selectedCategoryId = id;
selectedCategoryName = text.toString();
initCat(id);
}