roboguice inject in customer

acntwww

I have a widget View as below:
public class RemoteNumView extends FrameLayout {
how call I use Roboguice just as in RoboActivity? As below:

 @InjectView(R.id.btn_remote_control_num_0)
private TextView mText;

Full code is:

/**
* Created by bbcv on 13-12-12.
*/

public class RemoteNumView extends FrameLayout {
private IService mService;

@InjectView(R.id.btn_remote_control_num_0)
private TextView mText;

public RemoteNumView(Context context) {
    super(context);
    ///
    addView(LayoutInflater.from(context).inflate(R.layout.v_remote_control_fun,null));
}

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

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

public void setService(IService service){
    mService = service;
}
}

Anyone can HELP?

Lubos Horacek

Solved it by writing custom code. Roboguice is badly written for this purpose.

 protected void injectViews() {
    for (Field field : this.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(InjectView.class)) {
            if (Modifier.isStatic(field.getModifiers())) {
                throw new UnsupportedOperationException("Views can't be staticaly assigned.");
            } else {
                if (View.class.isAssignableFrom(field.getType())) {
                    try {
                        final InjectView injectView = field.getAnnotation(InjectView.class);
                        ;
                        final int id = injectView.value();
                        View view = findViewById(id);
                        if ((view == null) && Nullable.notNullable(field)) {
                            throw new NullPointerException(String.format("Can't inject null value into %s.%s when field is not @Nullable", field.getDeclaringClass(), field.getName()));
                        }
                        field.setAccessible(true);
                        field.set(this, view);
                    } catch (IllegalAccessException e) {
                        throw new IllegalStateException(e);
                    }
                } else {
                    throw new UnsupportedOperationException("Need view type to assign");
                }
            }
        }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

RoboGuice inject AnimatorSet

From Dev

Cannot inject view to custom class with RoboGuice

From Dev

When class injected by RoboGuice @Inject could be null?

From Dev

how to inject custom arrayadapter into fragment using roboguice 2.0

From Dev

How to inject a google guava eventbus as a global singleton using Roboguice in android?

From Dev

How can I inject "customer session" model in an observer in Magento 2

From Dev

Proguard with Roboguice

From Dev

RoboActionBarActivity for RoboGuice

From Dev

Proguard with Roboguice

From Dev

Lazy injection with Roboguice

From Dev

RoboGuice provision errors

From Dev

Use roboguice out of roboactivity

From Dev

injecting generics with roboguice

From Dev

Which version to use for RoboGuice

From Dev

Custom ActionBar and RoboGuice injection

From Dev

RoboGuice provision errors

From Dev

Roboguice crasshes app at launch

From Dev

Use roboguice out of roboactivity

From Dev

Installing Roboguice in Android Studio

From Dev

RoboGuice: how to use RoboGuice-provided injections in my custom class?

From Dev

Getting Mockito to work with RoboGuice and Robolectric

From Dev

Robolectric 2.0 & RoboGuice 2.0 Integration

From Dev

Proguard RoboGuice Obfuscate Error on ViewListener

From Dev

Android RoboGuice 3.0 nullpointer on toolbar

From Dev

How to make Roboguice 3.0 jar from sources

From Dev

Proguard - removing logs roboguice.util.Ln

From Dev

Android assisted injection with Factory using Roboguice not working

From Dev

RoboGuice: Using full reflection. Try using RoboGuice annotation processor for better performance

From Dev

Customer authenticate