- Forum posts: 3
May 24, 2017, 8:57:09 AM via Website
May 24, 2017 8:57:09 AM via Website
public class ProfileDefaultFragment extends Fragment{
public final String TAG = "ProfileDefaultFragment";
StudentProfileActivity activity;
Student student;
OverallData overallData;
List examResultData;
StudentProgressStatus studentProgress;
PieChart overAllPerChart;
TextView toNoDaysCnt;
TextView overallPrcnCnt;
ListView examlist;
ProfileExamResultAdapter profileExamResultAdapter;
ProfileChartsFragment profileChartsFragment;
BootstrapApplication bootstrapApplication = BootstrapApplication.getInstance();
private OnFragmentInteractionListener mListener;
public ProfileDefaultFragment() {
// Required empty public constructor
}
public void setStudent(Student studata){
student = studata;
}
public static ProfileDefaultFragment newInstance(String param1, String param2) {
ProfileDefaultFragment fragment = new ProfileDefaultFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
profileChartsFragment = new ProfileChartsFragment();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Intent studen_profile_defalt = getActivity().getIntent();
studentProgress = (StudentProgressStatus) studen_profile_defalt.getSerializableExtra("studentProgress");
View view = inflater.inflate(R.layout.fragment_profile_default, container, false);
toNoDaysCnt = (TextView) view.findViewById(R.id.txtNoofDaysCnt);
overallPrcnCnt = (TextView) view.findViewById(R.id.txtOverallPcntg);
overAllPerChart = (PieChart) view.findViewById(R.id.chartVariance);
overAllPerChart.setUsePercentValues(true);
//Setting Listview
examlist = (ListView) view.findViewById(R.id.list);
examlist.setAdapter();
Button btnMore = (Button) view.findViewById(R.id.btnMore);
btnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//getActivity().getIntent().putExtra("studentProgress",studentProgress);
android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
android.support.v4.app.FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.container, profileChartsFragment); // fragmen container id in first parameter is the container(Main layout id) of Activity
//transaction.addToBackStack("ProfileDefaultFragment"); // this will manage backstack
transaction.commit();
}
});
//examlist.setAdapter(profileExamResultAdapter);
return view;
}
public void onStart() {
super.onStart();
activity.setstudentProgress(studentProgress);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.activity = (StudentProfileActivity) activity;
setExamResults();
setOverallDataPnt();
try {
mListener = (ProfileDefaultFragment.OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
public String getPostQuery(){
String AcYr = "";
String PrID = "";
String CrID = "";
String DeptID = "";
String SemID = "";
String SecID = "";
String InId = "";
if ( studentProgress != null ) {
Log.d(TAG,"inside student progresssssssssss");
AcYr = studentProgress.getAcYr();
PrID = studentProgress.getPrID();
CrID = studentProgress.getCrID();
DeptID = studentProgress.getDepID();
SemID = studentProgress.getSemID();
SecID = studentProgress.getSecID();
}
return String.format
("{\"%s\":\"%s\"," +
"\"%s\":\"%s\"," +
"\"%s\":\"%s\"," +
"\"%s\":\"%s\"," +
"\"%s\":\"%s\"," +
"\"%s\":\"%s\"," +
"\"%s\":\"%s\"," +
"\"%s\":\"%s\"}",
"AcYr", AcYr,
"StuID", student.get_id(),
"PrID", PrID,
"CrID", CrID,
"DeptID", DeptID,
"SemID", SemID,
"SecID", SecID,
"InId", bootstrapApplication.getLogin().getInId()
);
}
public void setExamResults(){
new AsyncTask<Void, Void, ExamResultDataWrapper>(){
@Override
protected ExamResultDataWrapper doInBackground(Void... voids) {
HttpRequest request = post(bootstrapApplication.getURL_EXAMRESULT_STUDENT())
.contentType("application/json")
.header(HEADER_TOKEN_KEY,HEADER_TOKEN)
.send(getPostQuery());
String output = Strings.toString(request.buffer());
Log.d(TAG,output );
ExamResultDataWrapper response = null;
if(request.ok()) {
Gson gson = new GsonBuilder().create();
response = gson.fromJson(output, ExamResultDataWrapper.class);
}
return response;
}
@Override
protected void onPostExecute(ExamResultDataWrapper response) {
super.onPostExecute(response);
if( response!=null && response.getOutput()!= null) {
examResultData = response.getOutput().getData();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
public void setOverallDataPnt(){
new AsyncTask<Void, Void, OverallDataWrapper>(){
@Override
protected OverallDataWrapper doInBackground(Void... voids) {
if (NetworkUtil.isInternetAvailable()) {
try {
HttpRequest request = post(bootstrapApplication.getURL_GET_ATTENDANCELOG())
.contentType("application/json")
.header(HEADER_TOKEN_KEY, HEADER_TOKEN)
.send(getPostQuery());
String output = Strings.toString(request.buffer());
OverallDataWrapper response = null;
if (request.ok()) {
Gson gson = new GsonBuilder().create();
response = gson.fromJson(output, OverallDataWrapper.class);
}
return response;
}catch (Exception e){
e.printStackTrace();
}
}else {
NetworkUtil.showNetworkNotAvailable(getActivity());
}
return null;
}
@Override
protected void onPostExecute(OverallDataWrapper response) {
super.onPostExecute(response);
if( response!=null && response.getOutput().getData()!=null) {
overallData = response.getOutput().getData();
if (overallData.getOverallPrctg()!=null){
overallPrcnCnt.setText(overallData.getOverallPrctg()+ " %");
}else {
overallPrcnCnt.setText("-");
}
if (overallData.getTotalDayCnt()!= null && overallData.getTotalPntCnt() != null){
toNoDaysCnt.setText(overallData.getTotalPntCnt()+"/"+overallData.getTotalDayCnt());
}else if(overallData.getTotalDayCnt()!= null){
toNoDaysCnt.setText("-"+"/"+overallData.getTotalDayCnt());
}else
toNoDaysCnt.setText("-"+"/"+"-");
showChart();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
}
above is my code if i try to set adapter it shows error i cant find the error
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.