【发布时间】:2017-07-05 13:26:41
【问题描述】:
公共类 Slidetwo 扩展片段 {
private String mParam1;
private String mParam2;
String mon=String.valueOf(2);
String tue=String.valueOf(1);
String wed=String.valueOf(2);
String thur=String.valueOf(0);
String fri = String.valueOf(1);
String sat= String.valueOf(0);
String sun = String.valueOf(2);
String montab =String.valueOf(mon);
String tuetab = String.valueOf(tue);
String wedtab = String.valueOf(wed);
String thurstab = String.valueOf(thur);
String fritab = String.valueOf(fri);
String sattab = String.valueOf(sat);
String suntab = String.valueOf(sun);
String week = String.valueOf(mon+tue+wed+thur+fri+sat+sun);
int convertedVal = Integer.parseInt(week);
int finweek = (convertedVal/7);
int totalpercent= finweek;
String totalvaluedosage = String.valueOf(totalpercent);
private OnFragmentInteractionListener mListener;
public Slidetwo()
{
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment Slidetwo.
*/
// TODO: Rename and change types and number of parameters
public static Slidetwo newInstance(String param1, String param2)
{
Slidetwo fragment = new Slidetwo();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
//return inflater.inflate(R.layout.fragment_slidetwo, container, false);
View v = inflater.inflate(R.layout.fragment_slidetwo, container, false);
TextView txt1=(TextView)v.findViewById(R.id.montab);
if(txt1 !=null)
{
txt1.setText(montab);
}
TextView txt2=(TextView)v.findViewById(R.id.tuetab);
if(txt2 !=null)
{
txt2.setText(tuetab);
}
TextView txt3=(TextView)v.findViewById(R.id.wedtab);
if(txt3 !=null)
{
txt3.setText(wedtab);
}
TextView txt4=(TextView)v.findViewById(R.id.thurstab);
if(txt4 !=null)
{
txt4.setText(thurstab);
}
TextView txt5=(TextView)v.findViewById(R.id.fritab);
if(txt5 !=null)
{
txt5.setText(fritab);
}
TextView txt6=(TextView)v.findViewById(R.id.sattab);
if(txt6 !=null)
{
txt6.setText(sattab);
}
TextView txt7=(TextView)v.findViewById(R.id.suntab);
if(txt7 !=null)
{
txt7.setText(suntab);
}
ProgressBar simpleProgressBar1=(ProgressBar)v.findViewById(R.id.progressBarday1); // initiate the progress bar
simpleProgressBar1.setMax(100); // 100 maximum value for the progress value
// simpleProgressBar1.setProgress(100);
ProgressBar simpleProgressBar2=(ProgressBar)v.findViewById(R.id.progressBarday2); // initiate the progress bar
simpleProgressBar2.setMax(100); // 100 maximum value for the progress value
// simpleProgressBar2.setProgress(50);
ProgressBar simpleProgressBar3=(ProgressBar)v.findViewById(R.id.progressBarday3); // initiate the progress bar
simpleProgressBar3.setMax(100); // 100 maximum value for the progress value
//simpleProgressBar3.setProgress(100);
ProgressBar simpleProgressBar4=(ProgressBar)v.findViewById(R.id.progressBarday4); // initiate the progress bar
simpleProgressBar4.setMax(100); // 100 maximum value for the progress value
// simpleProgressBar4.setProgress(0);
ProgressBar simpleProgressBar5=(ProgressBar)v.findViewById(R.id.progressBarday5); // initiate the progress bar
simpleProgressBar5.setMax(100); // 100 maximum value for the progress value
// simpleProgressBar5.setProgress(20);
ProgressBar simpleProgressBar6=(ProgressBar)v.findViewById(R.id.progressBarday6); // initiate the progress bar
simpleProgressBar6.setMax(100); // 100 maximum value for the progress value
// simpleProgressBar6.setProgress(75);
ProgressBar simpleProgressBar7=(ProgressBar)v.findViewById(R.id.progressBarday7); // initiate the progress bar
simpleProgressBar7.setMax(100); // 100 maximum value for the progress value
// simpleProgressBar7.setProgress(50);
return v;
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
`实际上我在创建一个包含多个片段的应用程序时,我在一个活动中创建了三个进度条。根据正在打开的片段,进度条的数据应该改变,就像从一个片段滑动到另一个片段应该改变进度条的值。因此,如果你们中的任何人对如何实现这一点有任何想法,请帮助我:)
【问题讨论】:
标签: android android-fragments android-progressbar