开发者

onClickListener never called when used with timePicker

    timePicker = (TimePicker) findViewById(R.id.tijd);
    timePicker.setOnClickListener(this);


    klaar = (Button) findViewById(R.id.klaar);
    klaar.setOnClickListener(this);

Does anyone know why o开发者_运维技巧nly the Button triggers an onClick? The setOnClickListener on the timePicker doesn't seem to be working

edit: onclicklistener added, my main class implements onClickListener

    public void onClick(View v) {
        Log.d("temp", "View clicked");



}


What click are you trying to capture? There are several views inside a TimePicker; looking here, TimePicker has an OnTimeChangedListener you can use, which seems more like what you would want. I imagine you could do timePicker.setClickable(true) to set the entire view to be clickable, but I don't think that would give the results you're looking for. Alternatively, take a look at the TimePickerDialog example to see an example adapting a TimePicker into a dialog with a Set and Cancel button using an OnTimeSetListener.


First comment is sensible. We can't answer you until we read onClick() method. But I can suggest you to implement click listeners in separate methods:

timePicker = (TimePicker) findViewById(R.id.tijd);
timePicker.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // method for timePicker
    }
});


klaar = (Button) findViewById(R.id.klaar);
klaar.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // method for button
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜