Share Coding

Tutorials, Problems, Stuffs …

Tag Archives: android

Use Volley NetworkImageView with RecyclerView somet

Volley has a component NetworkImageView. It is easy to display image which is dowloaded from the network. However, working with RecyclerView or RecyclerViewPager, it load nothing on the view.

public class RecyclerNetworkImageView extends NetworkImageView {
    public RecyclerNetworkImageView(Context context) {
        super(context);
    }

    public RecyclerNetworkImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RecyclerNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onDetachedFromWindow() {
        // super.onDetachedFromWindow();
    }
}

When onDetachedFromWindow() being called, the following condition will stop loading image, so we override it through a subclass and it works!

if (mImageContainer != null) {
    // If the view was bound to an image request, cancel it and clear
    // out the image from the view.
    mImageContainer.cancelRequest();
    setImageBitmap(null);
    // also clear out the container so we can reload the image if necessary.
    mImageContainer = null;
}
Advertisements

EditText imeOption not working

When I press “enter” on the text field, it was supposed to do the send action.
But the unexpected “new line” action occur.

Read more of this post

Android DBFlow multiple condition query with ‘LIKE’ operator

In the following case, contain some features:

  1. ConditionGroup to handle multiple condition
  2. LIKE operator with “%”, means the keyword can have words in-front or after it

Read more of this post

GSON with reserved word in the data

When using GSON, a object class should be passed to the Gson parser.
How about if there is a field named ‘default’ or other JAVA reserved word in the data?

public class LockerImageSet {

    private String default;

    private String mapImage, buildingImage, lockerImage, aroundImage;

}

The following code shows how to do that by an annotation.

public class LockerImageSet {

    @SerializedName("default")
    private String defaultImage;

    private String mapImage, buildingImage, lockerImage, aroundImage;

}

Android Pass object between Intent

1. First of all, your Object class must be

implements Serializable

2. Package your parameter into a Bundle

User user1= new User("user1", "M");
Bundle bundle = new Bundle();
bundle.putSerializable("USER", user1);

Read more of this post