Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Fragment class calling json data and here i called that adapter consructor....
public class EAdFragment extends Fragment {
private ArrayList<hashmap><string,>> list;
ListView lvAdSurvey;
JSONObject json = null;
public static final String FIRST_COLUMN="First";
public static final String SECOND_COLUMN="Second";
JSONArray jarray=null;
JSONObject jsonObj=null;
public ListAdapter adapter;
public ArrayList<eadvertactivitydata> listData=new ArrayList<eadvertactivitydata>();
public void onViewCreated(View view, Bundle savedInstanceState){
lvAdSurvey=(ListView)view.findViewById(R.id.lvAdSurvey);
new GetList().execute();
//ListAdapter adapter=new SimpleAdapter(getActivity(), list, R.layout.column_ead, new String []{TAG_ID,TAG_NAME}, new int[]{R.id.tvAdSurvey,R.id.tvDescription});
EAdListViewAdapter adapter=new EAdListViewAdapter(this);
lvAdSurvey.setAdapter(adapter);
lvAdSurvey.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView int position, long id) {
// TODO Auto-generated method stub
String text = parent.getItemAtPosition(position).toString();
Log.d("text:",text);
Intent in =new Intent(getActivity(),AdvertActivity.class);
in.putExtra("user_id","A_00000013");
startActivity(in);
((Activity) getActivity()).overridePendingTransition(0,0);
}
});
}
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.fragment_ead, container, false);
return rootView;
}

private class GetList extends AsyncTask<string,> {

@Override
protected void onPreExecute() {
super.onPreExecute();
}

protected JSONObject doInBackground(String... args) {
// TODO Auto-generated method stub
//list=new ArrayList<hashmap><string,string>>();
listData=new ArrayList<eadvertactivitydata>();
String url = "http://sharpersofttech.com/sign_up/?tag=fetchall";
JSONParser jParser = new JSONParser();
jsonObj=jParser.getJSONFromUrl(url);
return jsonObj;
}

protected void onPostExecute(JSONObject jsonObject) {
try {
jarray=jsonObj.getJSONArray("result");
Log.d("lengtharray:",String.valueOf(jarray.length()));
for(int i=0;i<jarray.length();i++)>
{
EAdvertActivityData data=new EAdvertActivityData();

JSONObject jobject=new JSONObject(jarray.get(i).toString());
//HashMap<string,string> temp=new HashMap<string,>();
String upload_type=jobject.optString("Upl_ID").toString();
String description=jobject.optString("File_description").toString();
Log.d("upload_type",upload_type);
Log.d("description",description);
data.upl_ID=jobject.getString("Upl_ID");
data.file_description=jobject.getString("File_description");
//temp.put(FIRST_COLUMN, upload_type);
//temp.put(SECOND_COLUMN,description);
//list.add(temp);
listData.add(data);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}

public LayoutInflater getSystemService(String layoutInflaterService) {
// TODO Auto-generated method stub
return null;
}
}

adapter classs
public class EAdListViewAdapter extends BaseAdapter {

public ArrayList<hashmap><string,>> list;
Activity activity;
List<eadvertactivitydata> listData = null;
EAdFragment main;

EAdListViewAdapter(EAdFragment main) {
this.main = main;
}


public EAdListViewAdapter(Activity activity,List<eadvertactivitydata>
listData){ super(); this.activity=activity; this.listData=listData; }

@Override
public int getCount() {
// TODO Auto-generated method stub
return 11;//listData.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return listData.get(position);
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;// listData.indexOf(getItem(position));
}

private class ViewHolder {
TextView txtFirstColumn;
TextView txtSecondColumn;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.column_ead, null);
holder = new ViewHolder();
holder.txtFirstColumn = (TextView) convertView
.findViewById(R.id.tvAdSurvey);
holder.txtSecondColumn = (TextView) convertView
.findViewById(R.id.tvDescription);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// HashMap<string,> map=list.get(position);
holder.txtFirstColumn.setText(this.listData.get(position).upl_ID);
holder.txtSecondColumn
.setText(this.listData.get(position).file_description);
return convertView;
}
}
pojo class but i didn't use this class in this
public class EAdvertActivityData {

String upl_ID,file_description;


public EAdvertActivityData(String upl_ID,
String file_description) {
super();
this.upl_ID = upl_ID;
this.file_description = file_description;
}
public EAdvertActivityData() {
// TODO Auto-generated constructor stub
upl_ID=null;
file_description=null;
}
public String getUpl_ID() {
return upl_ID;
}
public void setUpl_ID(String upl_ID) {
this.upl_ID = upl_ID;
}
public String getFile_description() {
return file_description;
}
public void setFile_description(String file_description) {
this.file_description = file_description;
}
}
please suggest me any simle way of solving this problem and where the error in my code...
Posted
Updated 16-Nov-15 23:05pm
v2
Comments
Krunal Rohit 17-Nov-15 2:08am    
Apply the appropriate formatting your code here.

-KR

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900