Update Listview item after Callback

Asked

Viewed 67 times

0

In my application, I use the SDK of Parse.com. The SDK provides a method for loading API objects assíncrona and in another thread called fetchInBackground(). Within the getView() of my adapter happens the following:

ParseObject driver = object.getParseObject("object");
    driver.fetchInBackground(new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject parseObject, ParseException e) {
            if(e==null){
                item.name.setText(parseObject.getString("name"));
                notifyDataSetChanged();
            }
        }
});

I’m trying to set the name on item.name which is a TextView, but the name only appears when I scroll the list and return, in case when it loads the item again.

  • You knew Parse.com was going to die at the end of the year, right?

  • Yes @Leonardodias. But that doesn’t stop me from using their SDK, because it’s already been an existing project for a while.. Just clone their server..

1 answer

0

Try to use

     View v = suaListView.getChildAt(position);
     TextView textView = (TextView) v.findViewById(R.id.idSuaTextView);
     textView.setText(parseObject.getString("name");

or use Recyclerview and Recyclerview.Adapter in the method

    onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position){
        MyViewHolder holder = (MyViewHolder) viewHolder;

        holder.seuTextView.setText("Texto atualizado");

        notifyItemChanged(position);
     }

https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter.html

I hope I’ve helped :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.