Reputation: 240
I've created a method that is called when my EditText is clicked (or touched, to be specific), which simply takes the current time and displays it exactly as it has been passed by System.currentTimeMillis()
in a TextView below. The method is this one:
public void captureTime(View view) {
currentTime = System.currentTimeMillis();
String currentTimeStr = currentTime+ "";
TextView textView = findViewById(R.id.textView);
textView.setText(currentTimeStr);
}
To do that, I've had to add the code below in the onCreate
method. It uses setOnTouchListener
instead of setOnClickListener
since otherwise the captureTime
method wasn't always called. Now, this method does what I wanted, but now when I click or touch the EditText, although it does this as required, the keyboard doesn't show up anymore. I have looked into other questions in which the keyboard doesn't show up either but they're not related to my case, although I have tried them. So, what is that is making the keyboard not show up and how can I fix this?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add_time = (EditText)findViewById(R.id.editText);
add_time.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
captureTime(add_time);
return true;
}
return false;
}
});
}
Upvotes: 0
Views: 72
Reputation: 56
Try removing return true (in the if block). In this case, the "captureTime" method will work and the keyboard will open.
Upvotes: 1