Received data is not inflate to gridview - android

I have data model class and i download photos by json. And then i want to add theese photos in gridview. But i could not.
This download operation in onCreate(),
ProductHandler.setProducts(products);
final GridView gridView = (GridView) findViewById(R.id.gridView);
AsyncTaskListener asyncTaskListener = new AsyncTaskListener() {
#Override
public void onCompleted(String result) {
ArrayList<Product> products = ProductHandler.getProducts();
String json = "";
if(!Util.isNullOrEmpty(result)){
json = Html.fromHtml(result).toString();
}
if(!Util.isNullOrEmpty(json) && Util.isJSONValid(json)){
Log.e("json", json);
try {
JSONArray jsonArray = new JSONArray(json);
for(int i = 0; i < jsonArray.length(); i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
Product product = new Product();
product.setPhoto(jsonObject.getString("photo"));
products.add(product);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Log.e("after", String.valueOf(products.size()));
ProductAdapter adapter = new ProductAdapter(context, products);
gridView.setAdapter(adapter);
}
};
RequestParams requestParams = new RequestParams();
requestParams.add("api_key", Preferences.getSavedapiKey(context));
TaskParams taskParams = new TaskParams(Constant.API_PATH + "presentation.php", ClientMethod.POST, requestParams);
AsyncHttpClient asyncHttpClient = new AsyncHttpClient(asyncTaskListener);
asyncHttpClient.execute(taskParams);
ProductHandler is simple;
public class ProductHandler {
private static ArrayList<Product> products;
public static synchronized ArrayList<Product> getProducts(){
return products;
}
public static synchronized void setProducts(ArrayList<Product> products){
ProductHandler.products = products;
}
}
ProductAdapter;
public class ProductAdapter extends BaseAdapter {
private Context context;
private ArrayList<Product> products;
public ProductAdapter(Context context, ArrayList<Product> products){
this.context = context;
this.products = products;
}
#Override
public int getCount() {
return 0;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView == null){
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(0, 0, 0, 0);
} else{
imageView = (ImageView) convertView;
}
Util.Image.stringToImageView(imageView, products.get(position).getPhoto());
return imageView;
}
}
And products are define global in activity;
ArrayList<Product> products = new ArrayList<>();
So when it running, gridview is empty. I cannot understand the problem. Thank you.

Please pass your count in adapter(ProductAdapter)
#Override
public int getCount() {
return products.size();// you are passing 0 here
}

Related

Android ArrayList Adapter doesn't show the ListView

I have an ArrayList to represent in a ListView by an Adapter:
private ArrayList <Contact> listContacts = new ArrayList <Contact> ();
This is the (simple) Contact Class:
public class Contact {
String pic;
String name;
String surname1;
String surname2;
String phonenumber;
}
And this is the Adapter Class:
public class ContactsAdapter extends ArrayAdapter<Contact> {
private static class ViewHolder {
ImageView pic;
TextView name;
TextView surname1;
TextView surname2;
TextView phonenumber;
}
Context context;
public ContactsAdapter(Context context, int textViewResourceId, ArrayList<Contact> items) {
super(context, textViewResourceId, items);
this.context = context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(this.getContext())
.inflate(R.layout.layout_contact, parent, false);
holder = new ViewHolder();
holder.pic= (ImageView) convertView.findViewById(R.id.pic);
holder.name= (TextView) convertView.findViewById(name);
holder.surname1= (TextView) convertView.findViewById(R.id.surname1);
holder.surname2= (TextView) convertView.findViewById(R.id.surname2);
holder.phonenumber= (TextView) convertView.findViewById(R.id.phonenumber);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Contact item = getItem(position);
if (item!= null) {
int idImage = context.getResources().getIdentifier(item.pic, "drawable", context.getPackageName());
holder.pic.setImageResource(idImage);
holder.name.setText(item.name);
holder.surname1.setText(item.surname1);
holder.surname2.setText(item.surname2);
holder.phonenumber.setText(item.phonenumber);
}
return convertView;
}
}
The MainActivity is like this:
public class MainActivity extends ListActivity {
private ArrayList <Contact> listContacts = new ArrayList <Contact> ();
ContactsAdapter contactsAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
boolean result = loadListFromFiles();
if (result) {
loadContacts();
}
}
private void loadContacts() {
contactsAdapter = new ContactsAdapter(getApplicationContext(), R.layout.activity_main, listContacts);
setListAdapter(contactsAdapter);
}
The loadListFromFiles code:
private boolean loadListFiles(){
boolean result = false;
Context context = getApplicationContext();
File path = context.getFilesDir();
File[] files = path.listFiles();
Log.d("Files", "Size: "+ files.length);
for (int i = 0; i < files.length; i++)
{
Log.d("Files", "FileName:" + files[i].getName());
result = loadFile(files[i].getName());
}
return resultado;
}
private boolean loadFile(String fileName) {
String[] arrayContact = new String[4];
try
{
BufferedReader fin =
new BufferedReader(
new InputStreamReader(
openFileInput(fileName)));
int i = 0;
String line= "";
while ((line= fin.readLine()) != null) {
arrayContact[i] = linea;
i++;
}
fin.close();
Contact contact = new Contact();
contact.pic = arrayContact[3];
contact.name= arrayContact[0];
contact.surname1 = arrayContact[1];
contact.surname2 = arrayContact[2];
contact.phonenumber= arrayContact[3];
listContacts.add(contact);
return true;
}
catch (Exception ex)
{
Log.e("Files", "Error to read file by memory");
return false;
}
}
The ArrayList is right, but the layout don't show anything.
Override getCount() and getItem() methods to return count and contact item.
#Override
public int getCount() {
if(items == null)
return 0;
return items.size();
}
#Override
public Contact getItem(int i) {
return items.get(i);
}
Also, create one variable items in Adapter class and assign it to parameter passed to adapter constructor.
ArrayList<Contact> items;
public ContactsAdapter(Context context, int textViewResourceId, ArrayList<Contact> items) {
super(context, textViewResourceId, items);
this.context = context;
this.items = items;
}

android ListActivity how to populate data with Json Volley Library

android ListActivity how to make Custom Adapter getter setter using ,call json Volley library populate data ListActivity ? could not populate data with Json how to implement ,Please Help me
my code
ItemFragment Class
public class ItemFragment extends ListActivity {
RequestParse requestParse;
MySharedPreferences prefs;
String UsrId;
Context context;
ArrayList<BizForumArticleInfo> list = new ArrayList<>();
private List<BizForumArticleInfo> CountryCodeNumber = new ArrayList<>();
MobileArrayAdapter adapter;
LinearLayoutManager mLayoutManager;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view_android_example);
requestParse = new RequestParse();
prefs = MySharedPreferences.getInstance(this, SESSION);
UsrId = prefs.getString("UsrID", "");
context = getApplicationContext();
setListAdapter(new MobileArrayAdapter(this,0, list));
getJson(60);
}
public void getJson(final int limit){
requestParse.postJson(ConfigApi.postArticleBiz(), new RequestParse.VolleyCallBackPost() {
#Override
public void onSuccess(String result) {
list = parseResponse(result);
}
#Override
public void onRequestError(String errorMessage) {
}
#Override
public Map OnParam(Map<String, String> params) {
params.put("sessionid", UsrId);
params.put("offset", "0");
params.put("limit", String.valueOf(limit));
params.put("viewtype", "all");
params.put("access_token","e3774d357aa7d4bd14e9763b5459ee9cf7ebe36161c142551836ee510d98814a:b349b76b334a94b2");
return params;
}
});
}
public static ArrayList<BizForumArticleInfo> parseResponse(String response) {
ArrayList<BizForumArticleInfo> bizList = new ArrayList<>();
try {
JSONObject json = new JSONObject(response);
JSONArray data = json.getJSONArray(DATA);
for (int i = 0; i < data.length(); i++) {
BizForumArticleInfo ls = new BizForumArticleInfo();
JSONObject item = data.getJSONObject(i);
String ArticleTitle = item.getString("ArticleTitle");
String Article = item.getString("Article");
M.i("===================",ArticleTitle);//working
ls.setArticleTitle(ArticleTitle);
ls.setArticleArticle(Article);
bizList.add(ls);
}
} catch (JSONException e) {
e.printStackTrace();
}
return bizList;
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String selectedValue = (String) getListAdapter().getItem(position);
Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra("selectedValue", selectedValue);
setResult(RESULT_OK, intent);
finish();
//startActivity(new Intent(v.getContext(), MainActivity.class));
}
}
Adapter Class
public class MobileArrayAdapter extends ArrayAdapter<BizForumArticleInfo> {
private Activity activity;
private ArrayList<BizForumArticleInfo> lPerson;
private static LayoutInflater inflater = null;
public MobileArrayAdapter (Activity activity, int textViewResourceId,ArrayList<BizForumArticleInfo> _lPerson) {
super(activity, textViewResourceId, _lPerson);
try {
this.activity = activity;
this.lPerson = _lPerson;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
} catch (Exception e) {
}
}
public int getCount() {
return lPerson.size();
}
public BizForumArticleInfo getItem(BizForumArticleInfo position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView display_name;
public TextView display_number;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder;
try {
if (convertView == null) {
vi = inflater.inflate(R.layout.list_mobile, null);
holder = new ViewHolder();
holder.display_name = (TextView) vi.findViewById(R.id.label);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
holder.display_name.setText(lPerson.get(position).getArticleTitle());
} catch (Exception e) {
}
return vi;
}
}

GridView in a tab fragment is displayed only after scrolling to that tab second time

I have a fragment for a tab which displays JSON parsed results in GridView. The results are not displayed when scrolled to that tab for first time. But after switching tabs, results are displayed in second visit.
public class StoresFragment extends Fragment {
private ProgressBar loading;
private ArrayList<String> storenamefinal = new ArrayList<String>();
private ArrayList<Integer> imagelinksfinal = new ArrayList<Integer>();
private GridView gridview;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.stores_layout,null);
}
#Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
gridview = (GridView) getActivity().findViewById(R.id.grid_stores);
loading = (ProgressBar) getActivity().findViewById(R.id.proStores);
}
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
new getData(getActivity()).execute();
}
}
private class getData extends AsyncTask<Void, Void, Void> {
private Context context;
public getData(Context context) {
this.context = context;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Void doInBackground(Void... arg0) {
String url = Config1.DATA_URL;
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
showJSON(response);
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), error.getMessage().toString(), Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
requestQueue.add(stringRequest);
return null;
}
private void showJSON(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray("result");
int i = result.length();
Log.i("Result", result.toString());
for (int j = 0; j < i; j++) {
storenamefinal.add(null);
imagelinksfinal.add(null);
}
String temp;
for (int j = 0; j < i; j++) {
JSONObject Data = result.getJSONObject(j);
Log.i("Data", Data.toString());
temp = (Data.getString("mainpriority"));
Log.i("temp", temp.toString());
storenamefinal.set(Integer.parseInt(temp) - 1, Data.getString("storename"));
Log.i("Result Length", storenamefinal.toString());
imagelinksfinal.add(R.drawable.sg1);
}
Log.i("Result Length", storenamefinal.toString());
Toast.makeText(getActivity(), storenamefinal.get(0), Toast.LENGTH_LONG).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
protected void onPostExecute(Void result)
{
loading.setVisibility(View.GONE);
gridview.setVisibility(View.VISIBLE);
if (storenamefinal != null) {
final GridAdapterStores gridadapter = new GridAdapterStores(getActivity(), storenamefinal, imagelinksfinal);
gridview.setAdapter(gridadapter);
}
}
}
}
Adapter.
public class GridAdapterStores extends BaseAdapter {
private Context context;
private ArrayList<String> storename = new ArrayList<String>();
private ArrayList<Integer> imagelinks = new ArrayList<Integer>();
public GridAdapterStores(Context c, ArrayList<String> storename, ArrayList<Integer> imagelinks) {
context = c;
this.imagelinks = imagelinks;
this.storename = storename;
}
#Override
public int getCount() {
return storename.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
View grid;
if (convertView == null) {
grid = new View(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.grid_stores, parent, false);
} else {
grid = (View) convertView;
}
TextView textViewStoreName = (TextView) grid.findViewById(R.id.store_name);
// ImageView imageViewStoreImage = (ImageView) grid.findViewById(R.id.store_image);
textViewStoreName.setText(storename.get(position));
// Integer x=imagelinks.get(position);
// imageViewStoreImage.setImageResource(x);
return grid;
}
}
And also, everytime tab is switched, gridview gets added, but data is displayed in only one gridview.

android ListView is empty Logcat shows nothing

i am trying to display json data in listview but listview is empty logcat shows no error and app also don't get crashed i am unable to find the error here is the method that adds json data to the adapter
public void setTextToTextView(JSONArray jsonArray) {
contactAdapter = new ContactAdapter(this,R.layout.row_layout);
listView.setAdapter(contactAdapter);
try {
int count = 0;
String stop;
while(count < jsonArray.length())
{
JSONObject JO = jsonArray.getJSONObject(count);
stop = JO.getString("stop");
Contacts contacts = new Contacts(stop);
contactAdapter.add(contacts);
count++;
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
here is the Adapter class
public class ContactAdapter extends ArrayAdapter{
List list = new ArrayList();
public ContactAdapter(Context context, int resources){
super(context,resources);
}
public void add(Contacts object)
{
super.add(object);
list.add(object);
}
#Override
public int getCount() {return list.size();}
#Override
public Object getItem(int position) {return list.get(position);}
#Override
public View getView(int position,View convertView,ViewGroup parent)
{
View row;
row = convertView;
ContactHolder contactHolder;
if(row == null)
{
LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.row_layout,parent,false);
contactHolder = new ContactHolder();
contactHolder.tx_stop = (TextView)row.findViewById(R.id.tx_stop);
row.setTag(contactHolder);
}
else
{
contactHolder = (ContactHolder)row.getTag();
}
Contacts contacts = (Contacts)this.getItem(position);
contactHolder.tx_stop.setText(contacts.getStop());
return row;
}
static class ContactHolder
{
TextView tx_stop;
}
}
Call
contactAdapter.notifyDataSetChanged();
after your while loop.
You can create ArrayList<Contacts> contactsArray = new ArrayList<Contacts>(); then push all objects in it after that to set your adapter with passed array. Your method should look like:
public void setTextToTextView(JSONArray jsonArray) {
ArrayList<Contacts> contactsArray = new ArrayList<Contacts>();
try {
int count = 0;
String stop;
while(count < jsonArray.length()) {
JSONObject JO = jsonArray.getJSONObject(count);
stop = JO.getString("stop");
Contacts contacts = new Contacts(stop);
contactsArray.add(contacts);
count++;
}
contactAdapter = new ContactAdapter(this,R.layout.row_layout, contactsArray);
listView.setAdapter(contactAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
In your adapter do the following:
ArrayList<Contacts> list = new ArrayList<Contacts>();
public ContactAdapter(Context context, int resources, ArrayList<Contacts> list){
super(context,resources);
this.list = list;
}
That's all. Hope to help!

Adapter not displaying correct data

I am developing an application in which i am getting a large json data from the server. i want to display it in the list view. But i am getting the same value repeated. The no of items shown by the list view is proper. only same data repeated in all the list items.
Here is my code.
public class HistoryActivity extends AppCompatActivity {
private Toolbar toolbar;
String strServerResponse = null;
ProgressDialog nDialog;
ArrayList<String>clicklat;
ArrayList<String>clicklong;
ArrayList<String>dttime;
ArrayList<Pojo> history;
HistoryAdapter myAdapter;
ListView list;
public String date, inTime, outTime, inLat, inLong;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
toolbar = (Toolbar) findViewById(R.id.app_bar);
toolbar.setTitle("History");
clicklat=new ArrayList<String>();
clicklong=new ArrayList<String>();
dttime=new ArrayList<String>();
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
list = (ListView) findViewById(R.id.historyList);
history = new ArrayList<Pojo>();
new NetCheck().execute();
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ArrayList<String>clicklat= new ArrayList<String>(history.get(position).getLati());
ArrayList<String>clicklong= new ArrayList<String>(history.get(position).getLongi());
ArrayList<String>dttime= new ArrayList<String>(history.get(position).getDatetime());
Intent i = new Intent(HistoryActivity.this, DetailsActivity.class);
i.putStringArrayListExtra("clicklat", clicklat);
i.putStringArrayListExtra("clicklong", clicklong);
i.putStringArrayListExtra("clickdatetime", dttime);
startActivity(i);
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private class NetCheck extends AsyncTask<Void, Void, Void> {
#Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
nDialog.dismiss();
// TODO Auto-generated method stub
myAdapter = new HistoryAdapter(HistoryActivity.this, history);
list.setAdapter(myAdapter);
}
#Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpRequest = new HttpPost(
"http://myurl");
httpRequest.setHeader("Content-Type", "application/json");
SharedPreferences mmm = getSharedPreferences(
"MyPref", MODE_PRIVATE);
String logempid = mmm.getString("id", null);
JSONObject json = new JSONObject();
json.put("empid", logempid);
Log.e("JSON Object", json.toString());
StringEntity se = new StringEntity(json.toString());
se.setContentEncoding("UTF-8");
se.setContentType("application/json");
httpRequest.setEntity(se);
HttpResponse httpRes = httpClient.execute(httpRequest);
java.io.InputStream inputStream = httpRes.getEntity()
.getContent();
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
strServerResponse = sb.toString();
Log.e("Server Response", "" + strServerResponse.toString());
if (strServerResponse != null) {
try {
JSONArray arr = new JSONArray(strServerResponse);
for (int k = 0; k < arr.length(); k++) {
JSONObject jsonObj1 = arr.getJSONObject(k);
Pojo pojo = new Pojo();
JSONArray subArrayLat = jsonObj1.getJSONArray("lati_long");
List<String> lati= new ArrayList<String>();
List<String> longi= new ArrayList<String>();
List<String> dateandtime= new ArrayList<String>();
for (int i = 0; i < subArrayLat.length(); i++) {
String lat = subArrayLat.getJSONObject(i).getString("Latitude").toString();
String loong = subArrayLat.getJSONObject(i).getString("Longitude").toString();
String datetimee = subArrayLat.getJSONObject(i).getString("date_time").toString();
lati.add(lat);
longi.add(loong);
dateandtime.add(datetimee);
}
pojo.setLati(lati);//adding latitude list
pojo.setLongi(longi); //adding longitude list
pojo.setDatetime(dateandtime);
String dateee = arr.getJSONObject(k).getString("login_date");
String timeeee = arr.getJSONObject(k).getString("login_time");
String timeeee2 = arr.getJSONObject(k).getString("logout_time");
pojo.setDate(dateee);
pojo.setLoginTime(timeeee);
pojo.setLogoutTime(timeeee2);
history.add(pojo);
}
} catch (JSONException e) {
e.printStackTrace();
}
And this is Adapter
public class HistoryAdapter extends BaseAdapter {
private Context activity;
TextView tv_date;
TextView tv_loginTime;
TextView tv_logoutTime;
ArrayList<Pojo> list;
private ArrayList<Pojo> arraylist = null;
public static LayoutInflater inflater;
private Context context;
public HistoryAdapter(Context a, ArrayList<Pojo> history) {
// TODO Auto-generated constructor stub
activity = a;
list = history;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.arraylist = new ArrayList<Pojo>();
this.arraylist.addAll(list);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = convertView;
if(convertView == null) {
v = inflater.inflate(R.layout.history_item, parent, false);
}
final Pojo pojo = list.get(position);
tv_date = (TextView) v.findViewById(R.id.historyDate);
tv_loginTime = (TextView) v.findViewById(R.id.historyLoginTime);
tv_logoutTime = (TextView) v.findViewById(R.id.historyLogoutTime);
tv_date.setText(pojo.getDate());
tv_loginTime.setText(pojo.getLoginTime());
tv_logoutTime.setText(pojo.getLogoutTime());
return v;
}
}
and setters and getters
public class Pojo {
public static String empid11;
public static String loginTime;
public static String date;
public static String logoutTime;
public static List<String> lat;
public static List<String> datetime;
public static List<String> longi;
public static List<String> inlogin;
public static List<String> inDate;
public List<String> getInTime(){
return this.inlogin;
}
public List<String> getInDate(){
return this.inDate;
}
public void setInDate(List<String> inDate){
this.inDate = inDate;
}
public List<String> getLati(){
return this.lat;
}
public List<String> getLongi(){
return this.longi;
}
public void setLati(List<String> lat){
this.lat = lat;
}
public void setLongi(List<String> longi){
this.longi = longi;
}
public void setId(String empid) {
this.empid11 = empid;
}
public String getId() {
return empid11;
}
public void setLoginTime(String loginTime) {
this.loginTime = loginTime;
}
public String getLoginTime() {
return loginTime;
}
public void setLogoutTime(String logoutTime) {
this.logoutTime = logoutTime;
}
public String getLogoutTime() {
return logoutTime;
}
public void setDate(String date) {
this.date = date;
}
public String getDate() {
return date;
}
public List<String> getDatetime(){
return this.datetime;
}
public void setDatetime(List<String> datetime){
this.datetime = datetime;
}
}
Hello see the modifiy version of your adapter. Let me know if you have any problem with it.
public class HistoryAdapter extends BaseAdapter
{
private Context activity;
TextView tv_date;
TextView tv_loginTime;
TextView tv_logoutTime;
private ArrayList<Pojo> arraylist = null;
public static LayoutInflater inflater;
private Context context;
public HistoryAdapter(Context a) {
activity = a;
inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.arraylist = new ArrayList<Pojo>();
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public void addHistoryData(ArrayList<Pojo> newDataset){
if(arraylist != null){
arraylist.addAll(newDataset);
}
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder mViewHolder = null;
if(convertView == null)
{
mViewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.history_item, parent, false);
mViewHolder.tv_date = (TextView) convertView.findViewById(R.id.historyDate);
mViewHolder.tv_loginTime = (TextView)convertView.findViewById(R.id.historyLoginTime);
mViewHolder.tv_logoutTime = (TextView)convertView.findViewById(R.id.historyLogoutTime);
convertView.setTag(mViewHolder);
}else{
mViewHolder = (ViewHolder) convertView.getTag();
}
final Pojo pojo = list.get(position);
mViewHolder.tv_date.setText(pojo.getDate());
mViewHolder.tv_loginTime.setText(pojo.getLoginTime());
mViewHolder.tv_logoutTime.setText(pojo.getLogoutTime());
return v;
}
public class ViewHolder{
TextView tv_date
TextView tv_loginTime;
TextView tv_logoutTime;
}
}
In next the activity NetCheck class when web service response come change like below :
history.add(pojo);
myAdapter.addHistoryData(history);
myAdapter.notifiyDatasetChanged();
There may be problem you are getting repeated value in array, please check your array first.

Categories

Resources