You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Courses_ListView extends Fragment implements AsyncResponse {
//final String LOG="Courses_ListView";
final String LOG="Courses_ListView";
public ListView mListView;
List<String> items = new ArrayList<String>();
public String str = "";
DatabaseManagement dm=new DatabaseManagement(getContext());
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v=inflater.inflate(R.layout.fragment_courses_list_view,container,false);
return v;
}
@Override
public void onStart() {
super.onStart();
initControls();
}
public void initControls(){
mListView = (ListView) getView().findViewById(R.id.courseList);
PostResponseAsyncTask taskRead = new PostResponseAsyncTask(getContext(),this);
taskRead.execute("http://www.inductin.com/webservices/course_categories.php?request=ios");
populateListView();
}
@Override
public void processFinish(String s) {
Gson g=new Gson();
Courses c=g.fromJson(s,Courses.class);
Datum d=g.fromJson(s,Datum.class);
int count=c.getData().toArray().length;
// Toast.makeText(Courses_ListView.this, ""+count, Toast.LENGTH_SHORT).show();
Cursor res=dm.getAllData(dm,"SELECT * FROM course_categories");
int getCount=res.getCount();
if(getCount==0) {
for (int i = 0; i <= count; i++) {
boolean insert = dm.onInsert(dm, c.getData().get(i).getCategoryId(), c.getData().get(i).getCategoryName());
if (insert == true) {
Log.i("Database front end:", "Data has been inserted successfully");
} else {
Log.i("Database front end:", "Insert issue");
}
}
}
else if(count!=getCount){
dm.deleteAllData(dm,"course_categories");
for (int i = 0; i <= count; i++) {
boolean insert = dm.onInsert(dm, c.getData().get(i).getCategoryId(), c.getData().get(i).getCategoryName());
if (insert == true) {
Log.i("Database front end:", "Data has been inserted successfully");
} else {
Log.i("Database front end:", "Insert issue");
}
}
}
}
private void populateListView(){
Cursor cursor=dm.getAllRows(dm,"SELECT category_name FROM course_categories");
for( cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext() ) {
items.add(cursor.getString(0));
}
ArrayAdapter<String> adapter= new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,items);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l){
str= items.get(position);
Toast.makeText(getContext(),"You clicked:"+items.get(position),Toast.LENGTH_SHORT).show();
}
});
}
}
The above is my code. if something is wrong with my code then let me know but everytime i start my application and click on the option of the navigation drawer. The application closes.
The text was updated successfully, but these errors were encountered:
package com.peekatuts.inductin;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.kosalgeek.genasync12.AsyncResponse;
import com.kosalgeek.genasync12.PostResponseAsyncTask;
import java.util.ArrayList;
import java.util.List;
public class Courses_ListView extends Fragment implements AsyncResponse {
//final String LOG="Courses_ListView";
}
The above is my code. if something is wrong with my code then let me know but everytime i start my application and click on the option of the navigation drawer. The application closes.
The text was updated successfully, but these errors were encountered: