Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cards are not visible from Json response objects #111

Closed
ashokslsk opened this issue Sep 26, 2015 · 10 comments
Closed

Cards are not visible from Json response objects #111

ashokslsk opened this issue Sep 26, 2015 · 10 comments

Comments

@ashokslsk
Copy link

HI i have written my custom base adapter with json pojo and on succeful data retrieval i am setting the data to response object and response object to adapter and i have set the adapter to flingContainer like in the below code but i am not able to see the cards after i have parsed the data. please help on this

 client.get(getApplicationContext(), URL, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                String ResponseStr = new String(responseBody);
                gson = new Gson();
                Log.d("LIST", ResponseStr);
                responseObject = gson.fromJson(ResponseStr, SuggestionResponse.class);
                Adapter = new CardAdapter(MainActivity.this, responseObject.getUsers());
                flingContainer.setAdapter(Adapter);

            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            }
        });

And i have set the listners and implemented all the methods but still i am not able to see any out put
let me know i can share my adapter class as well my adapter looks like

import android.view.LayoutInflater;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dunst.flutter.R;
import com.dunst.flutter.netwrok.models.SuggestionResponse;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Ashu on 26/09/15.
 */
public class CardAdapter extends BaseAdapter {

    private List<SuggestionResponse.UsersEntity> mSuggestion;
    private Context mContext;
    private LayoutInflater inflater = null;

    public CardAdapter(Context mContext, List<SuggestionResponse.UsersEntity> mSuggestion) {
        this.mContext = mContext;
        this.mSuggestion = mSuggestion;
        inflater = ( LayoutInflater )mContext.
                getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mSuggestion.size();
    }

    @Override
    public Object getItem(int position) {
        return mSuggestion.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.each_card, parent, false);
        Holder holder = new Holder();
        holder.tv=(TextView) rowView.findViewById(R.id.textView1);
        holder.img=(ImageView) rowView.findViewById(R.id.imageView1);
        final SuggestionResponse.UsersEntity Suggestion = (SuggestionResponse.UsersEntity) getItem(position);
        holder.tv.setText(Suggestion.getFirstname());
        String Image_Url = Suggestion.getPhoto().get(0);
        Picasso.with(mContext).load(Image_Url).into(holder.img);
        rowView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            }
        });
        return rowView;
    }

    public class Holder
    {
        TextView tv;
        ImageView img;
    }
}
@alexwalterbos
Copy link

Do you call BaseAdapter.notifyDataSetChanged() anywhere? You should do this any time your data is updated or added.

@ashokslsk
Copy link
Author

Hello Hi alexwalterbos,

I tried your Solution in but still no response if you have any working example bro ?

   flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
            @Override
            public void removeFirstObjectInAdapter() {
                // this is the simplest way to delete an object from the Adapter (/AdapterView)
                Log.d("LIST", "removed object!");
                al.remove(0);
                arrayAdapter.notifyDataSetChanged();
            }

@alexwalterbos
Copy link

Now you update the arrayAdapter only in the removeFirstObjectInAdapter(). That won't get triggered until you swipe a card, which obviously doesn't happen because the cards are not shown. I'll look into it later today, I'm on mobile at the moment.

@alexwalterbos
Copy link

Try adding notifyDataSetChanged() after you first add the data, I'd say it should work after you've called flingContainer.setAdapter(Adapter).

@ashokslsk
Copy link
Author

Thanks i will try and let you know :)

On Tue, Oct 6, 2015 at 5:31 PM, Alex Walterbos notifications@github.com
wrote:

Try adding notifyDataSetChanged() after you first add the data, I'd say
it should work after you've called flingContainer.setAdapter(Adapter).


Reply to this email directly or view it on GitHub
#111 (comment).

@RajeshMobello
Copy link

Hi ashokslsk,

Did you fix that issue when add items from json respose

@ashokslsk
Copy link
Author

@RajeshMobello

Yes i have fixed that ...

@RajeshMobello
Copy link

@ashok

Could you share where you did change the code.

@ashokslsk
Copy link
Author

Hi @RajeshMobello ,

Please share where is your program struck my program is already in production.

@ttasterisco
Copy link

@RajeshMobello

you probably have this right now

[in your data fetch callback]
yourCustomAdapter = new CustomAdapter(getApplicationContext(), R.layout.view_card, yourData);
yourSwipeFlingAdapterView.setAdapter(yourCustomAdapter);

and it's not showing anything on the fling adapter view, right?

then adding mMixesAdapter.notifyDataSetChanged(); after setAdapter(...) should solve the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants