Please help me to implment the Button Action in below the Class
public class DoneButtonMain extends MainActivity implements OnClickListener{
private Activity activity;
private Context context;
public DoneButtonMain(Activity activity) {
this.activity=activity;
// TODO Auto-generated constructor stub
}
public View prepareControl(){
Button btn=new Button(activity);
btn.setText("Done");
btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btn.setBackgroundColor(Color.parseColor("#05a5a6"));
btn.setTypeface(Typeface.DEFAULT_BOLD);
btn.setPadding(7,7, 7, 7);
btn.setTextColor(Color.parseColor("#ffffff"));
return btn;
}
public LayoutParams prepareLayoutParam() {
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,RelativeLayout.TRUE);
param.addRule(RelativeLayout.CENTER_VERTICAL,RelativeLayout.TRUE);
param.rightMargin=20;
param.bottomMargin=20;
param.topMargin=20;
return param;
}
}
And MainActivity looks as below
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout parentlinLayout = new LinearLayout(this);
parentlinLayout.setOrientation(LinearLayout.VERTICAL);
LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
RelativeLayout raltivelayout1=new RelativeLayout(this);
raltivelayout1.setBackgroundColor(Color.parseColor("#1B4F91"));
//Button Added to the relativeLayaout
DoneButtonMain object=new DoneButtonMain(this);
raltivelayout1.addView(object.prepareControl(),object.prepareLayoutParam());
//Relative layout is added to the Linear View
parentlinLayout.addView(raltivelayout1);
}
i have tried to button.setOnClickListener
but i am getting a null pointer exception