I have created buttons onClick events to change the xml layout. When it comes to the implementation, the page of ViewPager turns blank instead of changing the layout successfully,Would you please tell me what should I change the onCreateVIew() ?
The below is my working :
public static void changeLayout(int index , final Activity activity){
Bundle data = new Bundle();
data.putInt("setting",index); // i chooses which layout to use on fragment 2
PlaceholderFragment f = new PlaceholderFragment();
f.setArguments(data);
FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
transaction.replace(R.id.pager, f);
transaction.addToBackStack(null);
transaction.commit();
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section number.
*/
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
private Button btn1;
private Button btn2;
private Button btn3;
private Button btn4;
private Button btn5;
private TextView tv1;
private TextView tv2;
private TextView tv3;
private TextView tv4;
private TextView tv5;
private ImageView dragImage;
private Button nameBank;
private Button normal;
private Button expert;
static boolean toggle = true ;
public PlaceholderFragment() {
}
int i = 0;
float viewRotation;
double fingerRotation;
double newFingerRotation;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_flight_bank_one, container, false);
System.out.println(getArguments().getInt("setting")) ;
int flag = getArguments().getInt("setting");
if(flag ==1 || flag ==0 ){
rootView = inflater.inflate(R.layout.fragment_flight_bank_one, container, false);
}else if(flag ==2){
rootView = inflater.inflate(R.layout.fragment_flight_bank_two, container, false);
}else if(flag ==3){
rootView = inflater.inflate(R.layout.fragment_flight_bank_three, container, false);
}else if(flag ==4){
rootView = inflater.inflate(R.layout.fragment_flight_bank_four, container, false);
}else if(flag ==5){
rootView = inflater.inflate(R.layout.fragment_flight_bank_five, container, false);
}
dragImage = (ImageView) rootView.findViewById(R.id.dragImage);
dragImage.setOnTouchListener(new OnTouchListener(){
private int _xDelta;
private int _yDelta;
@Override
public boolean onTouch(View v, MotionEvent event) {
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) dragImage
.getLayoutParams();
_xDelta = X - lParams.leftMargin;
// _yDelta = Y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams ParamsA = (RelativeLayout.LayoutParams) dragImage
.getLayoutParams();
ParamsA.leftMargin = X - _xDelta;
//ParamsA.topMargin = Y - _yDelta;
ParamsA.rightMargin = -250;
//ParamsA.bottomMargin = -250;
dragImage.setLayoutParams(ParamsA);
break;
}
// _root.invalidate();
return true;
// TODO Auto-generated method stub
}
});
..
System.out.print(dragImage.getRotation());
btn1 = (Button) rootView.findViewById(R.id.imageButton1);
btn2 = (Button) rootView.findViewById(R.id.imageButton2);
btn3 = (Button) rootView.findViewById(R.id.imageButton3);
btn4 = (Button) rootView.findViewById(R.id.imageButton4);
btn5 = (Button) rootView.findViewById(R.id.imageButton5);
tv1 = (TextView) rootView.findViewById(R.id.textViewLabel1);
tv2 = (TextView) rootView.findViewById(R.id.textViewLabel2);
tv3 = (TextView) rootView.findViewById(R.id.textViewLabel3);
tv4 = (TextView) rootView.findViewById(R.id.textViewLabel4);
tv5 = (TextView) rootView.findViewById(R.id.textViewLabel5);
setClick(btn1, rootView ,1 );
setClick(btn2, rootView ,2 );
setClick(btn3, rootView ,3 );
setClick(btn4, rootView ,4 );
setClick(btn5, rootView ,5 );
setText(resultUiString.get(112) , tv1 , isTablet);
setText(resultUiString.get(113) , tv2 , isTablet);
setText(resultUiString.get(114) , tv3 , isTablet);
setText(resultUiString.get(115) , tv4 , isTablet);
setText(resultUiString.get(116) , tv5 , isTablet);
double reducefactor = screenHeight * 1.0/1824 ;
if(reducefactor < 1.0){
while(reducefactor > 0.85){
reducefactor *=reducefactor;
}
}
System.out.println("reducefactor : " + reducefactor );
ColorTool.scaleButton(btn1 , reducefactor);
ColorTool.scaleButton(btn2 , reducefactor);
ColorTool.scaleButton(btn3 , reducefactor );
ColorTool.scaleButton(btn4 ,reducefactor );
ColorTool.scaleButton(btn5 , reducefactor );
nameBank = (Button) rootView.findViewById(R.id.imageViewBank);
normal = (Button) rootView.findViewById(R.id.imageViewMode1);
expert = (Button) rootView.findViewById(R.id.imageViewMode);
ColorTool.scaleButton(nameBank , reducefactor );
ColorTool.scaleButton(normal , reducefactor);
ColorTool.scaleButton(expert , reducefactor );
setClick(nameBank, rootView ,6 );
setClick(normal, rootView ,7 );
setClick(expert, rootView ,8 );
return rootView;
}
No comments:
Post a Comment