How do I replace a String[ ] with a ArrayList? - java

I'm trying to populate my gridview with images using picasso. I'm using jsoup to collect the image links and placing them into a ArrayList. I have something wrong with my ImageAdapter cause none of my images load when I start the app. My log shows the links being collected so that works. Any help will be appreciated. I'm posting the entire code for the Activity.
public class MainActivity extends Activity
{GridView grid;
String url="http://dstreet.site/";
String link,title,src;
ArrayList list= new ArrayList();
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Scrapper();
grid = (GridView)findViewById(R.id.grid);
grid.setAdapter(new ImageAdapter(this, list));
}
public class ImageAdapter extends BaseAdapter {
ArrayList list;
private LayoutInflater inflater;
Context c;
int mCount;
ImageAdapter(Context context, ArrayList list) {
inflater = LayoutInflater.from(context);
c = context;
mCount = list.size();
this.list=list;
}
#Override
public int getCount() {
return mCount;
}
#Override
public Object getItem(int position) {
return true;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View
convertView, ViewGroup parent) {
final ViewHolder holder;
View view = convertView;
if (view == null) {
view = inflater.inflate(R.layout.img, parent,
false);
holder = new ViewHolder();
assert view != null;
holder.imageView = (ImageView)
view.findViewById(R.id.image);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
Picasso.get()
.load(list.get(position))
.placeholder(R.drawable.ic_launcher)
.error(R.drawable.ic_launcher)
.fit()
.into(holder.imageView, new Callback() {
#Override
public void onError(Exception p1)
{holder.imageView.setVisibility(View.INVISIBLE);
// TODO: Implement this method
}
#Override
public void onSuccess() {
holder.imageView.setVisibility(View.VISIBLE);
}
});
return view;
}
}
static class ViewHolder {
ImageView imageView;
}
public void Scrapper()
{
Content content= new Content();
content.execute();
}
public class Content extends
AsyncTask<Void,Void,Void>
{
#Override
protected Void doInBackground(Void[] p1)
{
// TODO: Implement this method
try
{
Document doc = Jsoup.connect(url).get();
// Identify Table Class "worldpopulation"
for (Element table :
doc.select("div[class=poster]")) {
Elements imgSrc =
table.select("img[src]");
// Get only src from img src
src = imgSrc.attr("src");
list.add(src);
}
Log.d("image links",list.toString());
}
catch (IOException e)
{e.printStackTrace();
}
return null;
}
}}

If you want to replace String[] with ArrayList then you need to use ArrayList.get(position) instead of IMAGE_URLS [position].

It looks like you're not iterating over the elements after you queried the table for images:
for (Element table : doc.select("div[class=poster]")) {
Elements imgSrc = table.select("img[src]");
src = imgSrc.attr("src");
list.add(src);
}
Something like this should do it:
doc.select("div[class=poster]") // get list of div
.stream() // for each div
.map(table -> table.select("img[src]")) // find all images
.flatmap(Elements::stream) // collapse images into 1 list
.map(imgSrc -> imgSrc.attr("src")) // for each image
.forEach(list::add); // add to Collection

Related

ImageView in ListItem filter is not getting filtered in Android

I have a Search filter which has to filter the items based on the text input. Each list item consists of two TextViews and one ImageView. I have attached adapters and the filter is working fine with the two textviews but the corresponding ImageViews are not getting filtered (the order of images is not changing).
I tried to change the code in several ways but its not working. In here, my Adapter extends ArrayAdapter. I tried using the BaseAdapter too, but still doesn't work
My Adapter class:
import de.hdodenhof.circleimageview.CircleImageView;
public class ChefSearchResultAdapter extends ArrayAdapter<ChefSearchItem> implements Filterable {
private ArrayList<ChefSearchItem> modelValues;
private List<ChefSearchItem> mOriginalValues;
private Context context;
private static class ViewHolder {
TextView userName;
TextView userAdmirers;
CircleImageView userProfileImage;
}
public ChefSearchResultAdapter(Context context, ArrayList<ChefSearchItem> chefs) {
super(context, 0, chefs);
modelValues = chefs;
this.context=context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
ChefSearchItem chef = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
final ViewHolder viewHolder; // view lookup cache stored in tag
if (convertView == null) {
// If there's no view to re-use, inflate a brand new view for row
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.chef_search_listitem, parent, false);
viewHolder.userName = convertView.findViewById(R.id.user_name);
viewHolder.userAdmirers = convertView.findViewById(R.id.user_admirers);
viewHolder.userProfileImage = convertView.findViewById(R.id.profile_image);
// Cache the viewHolder object inside the fresh view
convertView.setTag(viewHolder);
} else {
// View is being recycled, retrieve the viewHolder object from tag
viewHolder = (ViewHolder) convertView.getTag();
}
final StorageReference storageReference = FirebaseStorage.getInstance().getReference("Users").child(chef.userUID);
storageReference.child("Profile Pic").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
#Override
public void onSuccess(Uri uri) {
//Picasso.get().load(uri).into(viewHolder.userProfileImage);
Picasso.get()
.load(uri)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(viewHolder.userProfileImage, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError(Exception e) {
Picasso.get()
.load(uri)
.into(viewHolder.userProfileImage, new Callback() {
#Override
public void onSuccess() {
}
#Override
public void onError(Exception e) {
Log.v("Picasso","Could not fetch image");
}
});
}
});
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception exception) {
// Handle any errors
}
});
// Populate the data from the data object via the viewHolder object
// into the template view.
viewHolder.userName.setText(chef.userName);
viewHolder.userAdmirers.setText(chef.userAdmirers);
//Set on click to listitem
LinearLayout listItem = convertView.findViewById(R.id.chef_listitem);
listItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Navigate user to selected chef profile
Intent i=new Intent(context,ChefsViewActivity.class);
i.putExtra("UID",chef.userUID);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
});
// Return the completed view to render on screen
return convertView;
}
#Override
public Filter getFilter() {
Filter filter = new Filter() {
#SuppressWarnings("unchecked")
#Override
protected void publishResults(CharSequence constraint, FilterResults results) {
modelValues.clear();
modelValues.addAll((ArrayList<ChefSearchItem>) results.values);
notifyDataSetChanged();
}
#Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
// Holds the results of a filtering values
List<ChefSearchItem> FilteredArrList = new ArrayList<>();
if (mOriginalValues == null) {
mOriginalValues = new ArrayList<>(modelValues); // saves
}
/********
*
* If constraint(CharSequence that is received) is null returns
* the mOriginalValues(Original) values else does the Filtering
* and returns FilteredArrList(Filtered)
*
********/
if (constraint == null || constraint.length() == 0) {
// set the Original result to return
results.count = mOriginalValues.size();
results.values = mOriginalValues;
} else {
Locale locale = Locale.getDefault();
constraint = constraint.toString().toLowerCase(locale);
for (int i = 0; i < mOriginalValues.size(); i++) {
ChefSearchItem model = mOriginalValues.get(i);
String data = model.userName;
if (data.toLowerCase(locale).contains(constraint.toString())) {
FilteredArrList.add(model);
}
}
// set the Filtered result to return
results.count = FilteredArrList.size();
results.values = FilteredArrList;
}
return results;
}
};
return filter;
}
}
My ViewHolder:
public class ChefSearchItem {
public String userName;
public String userAdmirers;
public String userUID;
public ChefSearchItem(String userName, String userAdmirers, String userUID) {
this.userName = userName;
this.userAdmirers = userAdmirers;
this.userUID = userUID;
}
}
More simpler way to filter out data is filter them locally
In your activity where your searchview is on submit call this method and pass the search string as parameter.
Make a temporary list which will consist of filterdata.
filter(String filter){
ArrayList<ChefSearchItem> filtereModelValues = new ArrayList<ChefSearchItem>();
for (ChefSearchItem chefSearchItem : <LIST YOU ARE SENDING TO ADAPTER>){
if(filter.toLowerCase().equals(chechefSearchItem.userUID.toLowerCase())
filtereModelValues.add(chefSearchItem );
}
//outside the for loop send the filtered list to adapter by creating method inside adapter name "filter" and pass filterList as parameter.
YOUR_ADAPTER.filter(filtereModelValues);
}
And in your adapter
public void filter(ArrayList<ChefSearchItem> filterModelValues){
modelValues = filterModelValues;
notifyDataChanged();
}

How to fetch an image from a url to an arrayList

I'm trying to show images that are read from a url, they are more than an image so I had to put all of them in an arraylist and then make the images display in a gridview, for some reason it's not showing anything, the gridview is completely blank, please advise what am I doing wrong.
BottomSheetDialog_Smiles.java
Communicator.getInstance().on("subscribe start", new Emitter.Listener() {
#Override
public void call(Object... args) {
try{
JSONDictionary response = (JSONDictionary) args[0];
String str = response.get("emojiPack").toString();
JSONArray emojies = new JSONArray(str);
for(int i=0;i<emojies.length();i++){
JSONObject response2 = (JSONObject)
emojies.getJSONObject(i);
emojiModel = new EmojiModel((String) response2.get("urlFile"));
emojiUrl = emojiModel.getEmojiFile();
Picasso.with(getApplicationContext()).load(emojiUrl);
JSONDictionary t = JSONDictionary.fromString(response2.toString());
emojiModel.init(t);
emojieModels.add(new EmojiModel(emojiUrl));
}
EmojiAdapter emojiAdapter = new EmojiAdapter(getApplicationContext(),
emojieModels);
gridView2.setAdapter(emojiAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
EmojiAdapter emojiAdapter = new EmojiAdapter(getApplicationContext(),
emojieModels);
gridView2.setAdapter(emojiAdapter);
EmojiAdapter.java
public class EmojiAdapter extends ArrayAdapter<EmojiModel> {
Context context;
ArrayList<EmojiModel> list = new ArrayList<>();
public EmojiAdapter(Context context,ArrayList<EmojiModel> list) {
super(context, R.layout.smiles_items_layout, list);
this.context = context;
this.list = list;
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater o =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = o.inflate(R.layout.gifts_layout_2, parent , false);
ImageView imageView = (ImageView) v.findViewById(R.id.smile_image_view);
imageView.setImageResource(Integer.parseInt((list.get(position)).urlFile));
return v;
}
}
EmojiModel.Java
public class EmojiModel {
private int id;
private int price;
public String urlFile;
public EmojiModel(String urlFile) {
this.urlFile=urlFile;
}
public String getEmojiFile() {
return urlFile;
}
public void init(JSONDictionary data){
try{
urlFile = (String) data.get("urlFile");
id = Integer.parseInt((String) data.get("id"));
price = Integer.parseInt((String) data.get("price"));
}catch(Exception e){
e.printStackTrace();
}
}
}
obviously this line of code wont work :
imageView.setImageResource(Integer.parseInt((list.get(position)).urlFile));
instead of that just use glide or piccaso to load pics.
first add this line to your gradle file :
implementation 'com.github.bumptech.glide:glide:4.5.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'
then instead of above line ,just write :
Glide.with(context).load(list.get(position)).urlFile).into(imageView);
also the picaso library is pretty same
also change your adapter in this way :
public class EmojiAdapter extends BaseAdapter {
Context context;
ArrayList<EmojiModel> list = new ArrayList<>();
public EmojiAdapter(Context context,ArrayList<EmojiModel> list) {
super(context, R.layout.smiles_items_layout, list);
this.context = context;
this.list = list;
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater o =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = o.inflate(R.layout.gifts_layout_2, parent , false);
ImageView imageView = (ImageView) v.findViewById(R.id.smile_image_view);
imageView.setImageResource(Integer.parseInt((list.get(position)).urlFile));
return v;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
}
Use Picasso in Adapter to show image
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater o =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = o.inflate(R.layout.gifts_layout_2, parent , false);
ImageView imageView = (ImageView) v.findViewById(R.id.smile_image_view);
Picasso.with(getApplicationContext()).load(list.get(position).getEmojiUrl()).into(imageView);
return v;
}
}

Android Icon/Image setting pattern for multiple choices

What pattern do I have to use, if I have ListView in which ImageView and like 500 different icons that could be set on that ImageView. Should I just write If/Switch statement, or there is another way/pattern to do it?. Thanks in advance!
Let me assume that you know what icon(I mean the name of icon) to be loaded into the imageView and those icons are available in your drawable resource folder. In this case
#Override
public void onBindViewHolder(final RecyclerAdapter.ViewHolder holder, int position) {
DataItem dataItem = dataList.get(holder.getAdapterPosistion());
try {
int resID = activityContext.getResources().getIdentifier(dataItem.getIconName() , "drawable"/**resource folder name*/, activityContext.getPackageName());
holder.imageView.setBackgroundResource(resID);
} catch (Exception e) {
throw new RuntimeException("Error getting Resource ID.", e)
}
}
Where are these icons that you want to set? you are getting them from server or they are stored locally in your application file? or they are from user phone gallery?
Here is the code you want for your adapter:
public class MyAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
private ArrayList<String> mIconNames;
public MyAdapter(Context context) {
mContext = context;
mIconNames = getIconNames();
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return mIconNames.size();
}
#Override
public Object getItem(int position) {
return mIconNames.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get view for row item
View rowView = mInflater.inflate(R.layout.your_layout, parent, false);
ImageView thumbnailImageView =
(ImageView) rowView.findViewById(R.id.your_image_view_id);
Picasso.with(mContext).load(mIconNames.get(position)).placeholder(R.mipmap.ic_launcher).into(thumbnailImageView);
return rowView;
}
//this method builds your icon names
private ArrayList<String> getIconNames() {
ArrayList<String> iconNames = new ArrayList<>();
int numberOfIcons = 99;
String iconBaseName = "icon";
for (int i = 1; i < numberOfIcons; i++) {
iconNames.add(iconBaseName + i);
}
return iconNames;
}
}

How to load a new template on a selected grid view item in android

I'm new at android. and I want to load a new template which contains two button on a selected item of grid view object.
Is that possible.
I added a gridview to my project and by using base adapter a template was loaded to each item of gridview. But what I want is that when I clicked an item of gridview, I want to load a new template (layout) to the selected item.
THE PROBLEM WAS SOLVED, followings are the edited codes
Base Adapter
public class KategoriAdapter extends BaseAdapter{
private Context mContext;
private String[] categoryValues;
private Bitmap[] pictures;
//indicate that positon for new template
private int mNewTemplatePos = -1;
public KategoriAdapter(Context context, String[] categoryValues, Bitmap[] pictures) {
this.mContext = context;
this.categoryValues = categoryValues;
this.pictures = pictures;
}
//apply new template to positon
public void useNewTemplate(int pos) {
mNewTemplatePos =pos;
//notiy list that data has changed and the list will refresh ui itself.
notifyDataSetChanged();
}
#Override
public int getCount() {
return categoryValues.length;
}
#Override
public Object getItem(int possition) {
return null;
}
#Override
public long getItemId(int possition) {
return 0;
}
#Override
public View getView(int possition, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int posId = mNewTemplatePos;
if (convertView == null){
if (mNewTemplatePos ==possition){
convertView = getNewTemplate(inflater,possition);
}else {
convertView = getNormalTemplate(inflater,possition);
}
}else {
if (posId==possition){
convertView = getNewTemplate(inflater,possition);
}else{
convertView = getNormalTemplate(inflater,possition);
}
}
return convertView;
}
private View getNormalTemplate(LayoutInflater inflater, int possition) {
final View grid = inflater.inflate(R.layout.kategoriler_list_item, null);
TextView cName = (TextView) grid.findViewById(R.id.grid_item_ad);
ImageView categoryPictures = (ImageView) grid.findViewById(R.id.grid_item_resim);
cName.setText(categoryValues[possition]);
categoryPictures.setImageBitmap(pictures[possition]);
return grid;
}
private View getNewTemplate(LayoutInflater inflater, int possition) {
final View grid = inflater.inflate(R.layout.kategori_secenek_template, null);
TextView cName = (TextView) grid.findViewById(R.id.grid_item_ad);
cName.setText(categoryValues[possition]);
Button btn_nesne_tani = (Button) grid.findViewById(R.id.btn_nesneleri_taniyalim);
Button btn_cumle_kur = (Button) grid.findViewById(R.id.btn_cumle_kuralim);
btn_nesne_tani.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,"nesne",Toast.LENGTH_SHORT).show();
}
});
btn_cumle_kur.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,"cümle",Toast.LENGTH_SHORT).show();
}
});
return grid;
}
}
KategoriActivity.java
.....
final KategoriAdapter adapter = new KategoriAdapter(getApplicationContext(), mKategoriler, kategoriResimleri);
grid=(GridView)findViewById(R.id.gv_kategoriler);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
adapter.useNewTemplate(position);
Toast.makeText(getApplicationContext(), mKategoriler[position].toString(),Toast.LENGTH_SHORT).show();
}
});
}
I have rewrite your KategoriAdapter class:
public class KategoriAdapter extends BaseAdapter {
private Context mContext;
private final String[] categoryValues;
private final Bitmap[] pictures;
//indicate that positon in list are all use new template
private List<Integer> mNewTemplatePos;
public ImageView categoryPictures;
//indicate that this is normal template view
private final String NORMAL_TEMPLATE = "NORMAL_TEMPLATE";
//indicate that this is new template view
private final String NEW_TEMPLATE = "NEW_TEMPLATE";
public KategoriAdapter(Context context, String[] categoryValues, Bitmap[] pictures) {
this.mContext = context;
this.categoryValues = categoryValues;
this.pictures = pictures;
this.mNewTemplatePos = new ArrayList<>();
}
//apply new template to positon
public void useNewTemplate(int pos) {
mNewTemplatePos.add(pos);
//notiy list that data has changed and the list will refresh ui itself.
notifyDataSetChanged();
}
#Override
public int getCount() {
return categoryValues.length;
}
#Override
public Object getItem(int possition) {
return null;
}
#Override
public long getItemId(int possition) {
return 0;
}
#Override
public View getView(int possition, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
if (mNewTemplatePos.contains(possition)) {
convertView = getNewTemplate(inflater, possition);
//use tag to indicate the type of the template
convertView.setTag(NEW_TEMPLATE);
} else {
convertView = getNormalTemplate(inflater, possition);
convertView.setTag(NORMAL_TEMPLATE);
}
} else {
switch ((String) convertView.getTag()) {
case NORMAL_TEMPLATE:
//convertView is the normal template view but you need a new template view in possition
if (mNewTemplatePos.contains(possition))
convertView = getNewTemplate(inflater, possition);
break;
case NEW_TEMPLATE:
//convertView is the new template view but you need a normal template view in possition
if (!mNewTemplatePos.contains(possition))
convertView = getNormalTemplate(inflater, possition);
break;
}
}
return convertView;
}
private View getNormalTemplate(LayoutInflater inflater, int possition) {
View grid = inflater.inflate(R.layout.kategoriler_list_item, null);
TextView cName = (TextView) grid.findViewById(R.id.grid_item_ad);
categoryPictures = (ImageView) grid.findViewById(R.id.grid_item_resim);
cName.setText(categoryValues[possition]);
categoryPictures.setImageBitmap(pictures[possition]);
return grid;
}
private View getNewTemplate(LayoutInflater inflater, int possition) {
// TODO: 31/08/16 inflate you new template view layout here
return youNewTemplateView;
}
}
You should determine wether if current contentView is the right template type in getView() because contentView may be one of the new template in your list when it is not null.It is convenient to use tag to indicate the template type.
When to use useNewTemplate(position)?
Just apply the position that you need to use new template to useNewTemplate() and use it in your onItemClick() method.
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
useNewTemplate(position);
}
});

ListView displays arraylist data twice

Can anyone help me with figuring out why my listview repeats the results it gets from the database. I am using a Listview with Checkbox. Here is my code below.
public class AccessLevels extends Fragment {
MyAdminAdapter adminAdapter = null;
Guards guards;
ListView listView;
public ArrayList<Guards> guardsName;
public String str_name;
public boolean isAdmin;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_access_levels, container, false);
listView = (ListView)view.findViewById(R.id.list_of_guards);
return view;
}
private class MyAdminAdapter extends ArrayAdapter<Guards>{
private ArrayList<Guards> objectsList;
public MyAdminAdapter(Context context, int resource, ArrayList<Guards> objectsList) {
super(context, resource, objectsList);
this.objectsList = objectsList;
this.objectsList.addAll(objectsList);
}
private class ViewHolder{
CheckBox chk_name;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null){
LayoutInflater vi = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.single_row_access, null);
holder = new ViewHolder();
holder.chk_name = (CheckBox) convertView.findViewById(R.id.chk_guard);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
final Guards guards = objectsList.get(position);
holder.chk_name.setText(guards.getName());
holder.chk_name.setChecked(guards.isChecked());
holder.chk_name.setTag(guards);
holder.chk_name.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Guards guards = (Guards) cb.getTag();
guards.setChecked(cb.isChecked());
}
});
return convertView;
}
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public void onDetach() {
super.onDetach();
}
}
I get the data an store it like this.
private void DisplayAllNames() {
guardsName = new ArrayList<Guards>();
ParseQuery<ParseObject> guardsQuery = ParseQuery.getQuery("Guards");
guardsQuery.whereExists("Name");
guardsQuery.orderByAscending("Name");
guardsQuery.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
if (list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
ParseObject data = list.get(i);
str_name = data.getString("Name");
isAdmin = data.getBoolean("admin");
guards = new Guards(str_name, isAdmin);
guardsName.add(guards);
}
adminAdapter = new MyAdminAdapter(getActivity(), R.layout.single_row_access, guardsName);
listView.setAdapter(adminAdapter);
} else {
}
} else {
}
}
});
}
Thanks in advance.
Remove this line from your MyAdminAdapter's constructor:
this.objectsList.addAll(objectsList);
You are already adding your items in the previous instruction:
this.objectsList = objectsList;
In your MyAdminAdapter you are adding the data twice:
this.objectsList = objectsList;
this.objectsList.addAll(objectsList);
You just have to remove the second line.

Categories

Resources