Is there a getContentView method like setContentview?
I need to get the layout name or layout id in the onKeyDown method. Is there a way to find the current layout name.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
return true;
}
return super.onKeyDown(keyCode, event);
}
+1
source to share
1 answer
use the following code.
class myactivity extends Activity{
int layoutid;
@Override
public onCreate(Bundle b){
setContentView(R.id.mainlayout);
layoutid = R.id.mainlayout;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// here you can access the layoutid variable
// implement your logic here
return true;
}
return super.onKeyDown(keyCode, event);
}
}
enjoy...
+3
source to share