Sreepulari Sreepulari - 24 days ago 12
Android Question

.init(activity); is showing error [android]

i am trying to implement ShineButton in my project . I have successfully synced the library to the gradle and added shine button in the xml.

now when i am trying to write the java code

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


Button b1 = (Button)findViewById(R.id.button);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Kill bill", Toast.LENGTH_SHORT).show();
}
});


ShineButton shineButton = (ShineButton) findViewById(R.id.po_image2);
shineButton.init(context);

}
}





.init(activity); is showing cannot resolve symbol activity.

Answer

You don't literally copy the code verbatim, you read the documentation and object types supported by the method.

public void init(Activity activity) {

For example, I assume you are running that from an activity based on the usage of findViewById? Then you need "this instance of the Activity"

shineButton.init(this);

or an instance of an Activity if you were in a Fragment

shineButton.init(getActivity());
Comments