背景::
我正在使用DOUBLE ENDED SEEKBAR
这里显示
我想做什么::
- 我在双端搜索栏中设置值
- 在方向更改时,我想存储选择并借助
onSaveInstanceState
- 我怎样才能做到这一点
FrgMdFilter.java
public class FrgMdFilter extends Fragment {
//Declaring View Objects references
private Button btnFilterList;
private Spinner spinViewBy;
private TextView txtMinPrice,txtMaxPrice,txtMinDistance,txtMaxDistance,txtMinRating,txtMaxRating;
private CheckBox chkPrice,chkDistance,chkRating;
//Declaring Objects Declaration references
private ArrayList<HashMap<String, String>> objListBufType=null;
private FragmentTransaction ft;
private Fragment objFragment=null;
private static String errMsg=null;
private static boolean isErr=false;
//Constructor declaration on type newInstance
public static FrgMdFilter newInstance() {
FrgMdFilter fragment = new FrgMdFilter();
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.frg_md_filter, container, false);
try {
//For using actionbar menu from fragment
setHasOptionsMenu(true);
//For retaining fragment on configuration changes
setRetainInstance(true);
//Set the Application Variable to track Which class is currently loaded to the container
AppController.CURRENT_FRAGMENT=FrgMdFilter.class.getSimpleName();
//Set the title and sub-title for mobiles having API>=11
if (android.os.Build.VERSION.SDK_INT >= 11) {
//Set the title and sub-title for the actionbar
ActionBar ab = getActivity().getActionBar();
ab.setTitle(getResources().getString(R.string.app_name));
ab.setSubtitle(getResources().getString(R.string.FrgMdFilterScreenName));
}
objListBufType=new ArrayList<HashMap<String, String>>();
} catch (Exception e) {
if(isErr==false){
errMsg=e.toString();
isErr=true;
//Pop the dialog
DlgUniversalError.showQuitAlert(getActivity(),errMsg);
}
}
return view;
}
@Override
public void onStart() {
super.onStart();
try {
int minOnlinePrice=Integer.valueOf(txtMinPrice.getText().toString());
int maxOnlinePrice=Integer.valueOf(txtMaxPrice.getText().toString());
// create RangeSeekBar as Integer range between 20 and 75
UtilRangeSeekBar<Integer> seekBarPrice = new UtilRangeSeekBar<Integer>(minOnlinePrice, maxOnlinePrice, getActivity().getApplicationContext());
seekBarPrice.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>() {
@Override
public void onRangeSeekBarValuesChanged(UtilRangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
// handle changed range values
txtMinPrice.setText(String.valueOf(minValue));
txtMaxPrice.setText(String.valueOf(maxValue));
if(chkPrice.isChecked()!=true){
chkPrice.setChecked(true);
}
}
});
ViewGroup layoutPrice = (ViewGroup) getActivity().findViewById(R.id.seekPriceBar);
layoutPrice.addView(seekBarPrice);
} catch (Exception e) {
if(isErr==false){
errMsg=e.toString();
isErr=true;
//Pop the dialog
DlgUniversalError.showQuitAlert(getActivity(),errMsg);
}
}
}
private void initializeSeekBar() throws Exception {
DatabaseHandler mHelper;
SQLiteDatabase db = null;
Cursor mCursor = null;
try {
mHelper = new DatabaseHandler(getActivity());
db = mHelper.getReadableDatabase();
mCursor = db.rawQuery("select Min(online_price),Max(online_price),Min(rating),Max(rating),Min(distance),Max(distance) " +"from "+ view_buffet.VIEW_NAME_VW_BUFFET, null);
if (mCursor.getCount()>0) {
//It is a necessary to move the cursor to the beginning every time we perform the cursor operation
mCursor.moveToFirst();
/* Math.floor:: Rounding to low value
* Math.ceil:: Rounding to high value*/
txtMinPrice.setText(String.valueOf(Integer.valueOf((int) Math.floor(Integer.valueOf(mCursor.getString(0))))));
txtMaxPrice.setText(String.valueOf(Integer.valueOf((int)
}
} catch (Exception e) {
if(isErr==false){
errMsg=e.toString();
isErr=true;
throw e;
}
}finally{
if(db!=null){
if(db.isOpen()) db.close();
}
if(mCursor!=null){
if(!mCursor.isClosed())mCursor.close();
}
}
}
@Override
public void onCreateOptionsMenu(
Menu menu, MenuInflater inflater) {
//Now inflate the menu items required
inflater.inflate(R.menu.screen_refresh, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
ft = getFragmentManager().beginTransaction();
switch(item.getItemId()) {
case R.id.screen_refresh:
//REFRESH THE FRAGMENT
getFragmentManager().beginTransaction().remove(objFragment).commit();
objFragment = FrgMdFilter.newInstance();
getFragmentManager().beginTransaction().add(R.id.content_frame, objFragment,"FrgMdFilter").commit();
return true;
}
return super.onOptionsItemSelected(item);
}
}