Issue
I am using a fragment in which i used back event for webview but still it loads history when i click back. How to overcome in fragments.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN){
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
if(mWebView.canGoBack() == true){
mWebView.goBack();
}else{
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
but still it loads previous history. Thanks in advance.
Solution
Aa extends Fragment
{
static WebView w;
View v;
private Handler handler = new Handler(){
@Override
public void handleMessage(Message message) {
switch (message.what) {
case 1:{
webViewGoBack();
}break;
}
}
private void webViewGoBack() {
w.goBack();
// TODO Auto-generated method stub
}
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
v = inflater.inflate(R.layout.webs, container, false);
w=(WebView)v.findViewById(R.id.webView1);
}
w.setOnKeyListener(new OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if((keyCode==KeyEvent.KEYCODE_BACK)&& w.canGoBack())
{
handler.sendEmptyMessage(1);
return true;
}
return false;
}
});
Answered By - Shadow
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.