I have a popup implemented inside an Activity,and i'm trying to add onclicklistener to it,but it shows an error "Trying to invoke virtual method on a null object reference",but i checked the id of the edittext,which is "date_from" in popupdashboard.xml,am i missing something,do i need to add a reference for popdashboard.xml somewhere ??
public class DashboardActivity2 extends AppCompatActivity implements View.OnClickListener {
ImageView image;
EditText datefrom,dateto;
TextView amo_today,amo_yest,increase,percent;
private PopupWindow active;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard2);
datefrom = (EditText)findViewById(R.id.date_from);
datefrom.setOnClickListener(this);
dateto = (EditText)findViewById(R.id.date_to);
dateto.setOnClickListener(this);
any help would be appreciated
Below code contain setup for showing popup window
active = new PopupWindow(ctx);
inflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = R.layout.popupdashboard;
contentView = inflater.inflate(layout, null);
datefrom = (EditText) contentView.findViewById(R.id.date_from);
active.setHeight(LayoutParams.WRAP_CONTENT);
active.setWidth(LayoutParams.WRAP_CONTENT);
active.setContentView(contentView);
active.showAtLocation(anchor, Gravity.NO_GRAVITY, position_x,
position_y);