Android if I use WebView.destroy() can I restore it later? - java

So my question is simple if I use the WebView.destroy() in my app can I restore WebView to it's original state when the app was first initialize with out closing my app and opening it again? and how can I do this? I just want to be able to press a button and have this button rebuild my WebView and load a new url. I need to destroy it no just set it GONE or INVISIBLE.
Thanks
UPDATE:
Button rbesatbtn = (Button) findViewById(R.id.btnrbesa);
rbesatbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
wvr.destroy()
}
});
Button resttbtn = (Button) findViewById(R.id.btnrrest);
rrestbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
WebView wvr = new WebView(this);
setContentView(wvr);
wvr = (WebView) findViewById(R.id.wVradios);
wvr.getSettings().setJavaScriptEnabled(true);
wvr.getSettings().setPluginsEnabled(true);
wvr.setWebViewClient(new WebViewClient());
wvr.setInitialScale(1);
wvr.getSettings().setBuiltInZoomControls(true);
wvr.getSettings().setUseWideViewPort(true);
});

The documentation says:
Destroy the internal state of the WebView. This method should be called after the WebView has been removed from the view system. No other methods may be called on a WebView after destroy.
So I guess that the answer is no. However, you can always initialize a new one...

Related

Is it impossible to have ListvVew in Custom Dialog?

If the showChatList() function is not being called in the code, and the dialog is displayed normally.
When the listView is called via showChatList() function, it does not work.
To the original custom dialog
Is it impossible to bring up the listView?
public void callFunction() {
final Dialog dlg = new Dialog(context);
dlg.setContentView(R.layout.room_list);
dlg.show();
final Button okButton = (Button) dlg.findViewById(R.id.okButton);
final Button backbtn = (Button) dlg.findViewById(R.id.backbtn);
**final ListView chat_list = (ListView) dlg.findViewById(R.di.chat_list);**
- or
**chat_list = dlg.findViewById(R.id.chat_list);**
backbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dlg.dismiss();
}
});
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dlg.dismiss();
}
});
showChatList();
}
Your adapter depends on firebase.
It will wait until it gets data,
then I believe you need to call
adapter.notifyDataSetChanged();
after
adapter.add();
When dealing with views like dialogs, it is important to load all the views needed in the dialog before calling dialog.show().
Alternatively, I'll suggest the use of DialogFragment with this example: https://blog.mindorks.com/implementing-dialog-fragment-in-android.
DialogFragments allow you to manage your dialogs just like any other fragment.
Let me know which one you're able to use.

Opening datepicker dialog on click of a programmatically created editext?

I've found numerous tutorials on how to accomplish this when you can grab the textview from the xml but nothing on how to implement such a function when you have multiple edit texts created programmatically that all need the same functionality.
After you create the EditText, you would add a click listener the same way you would to any other view. You may also need to disable the focusable attribute to prevent clicks from activating the keyboard:
editText.setFocusable(false);
editText.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Open dialog here
}
});
If you have all EditText's, simply create one OnClickListener, call setOnClickListener on every EditText and pass the OnClickListener Object.
View.OnClickListener listener = new View.OnClickListener() {
#Override
public void onClick(View v) {
//open dialog here;
}
};
editText1.setOnClickListener(listener);
editText2.setOnClickListener(listener);
You should maybe store the EditText's in an array, so that you can just loop through all of them.

Android moving from one app to another

I have two separate apps. the packages are as follows:
com.example.incrediblemachine.rnt
com.example.incrediblemachine.palpal
i would like to do the following:
when clicked on a button on the rnt app, i want the palpal app to open.
is there any way to do this?
Use getLaunchIntentForPackage method in your Button onClick() . Before that install com.example.incrediblemachine.palpal app in device /emulator.
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.incrediblemachine.palpal");
startActivity(launchIntent);
}
});

Double Click on Button Android

First off this question has been asked multiple times, however, none of these questions have been answered to any extent. I have one example that works in the main activity class:
final Button button = (Button) findViewById(R.id.viewcatalog);
button.setFocusable(true);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.find_item);
}
});
But all of my other attempts to replicate this in sequential pages has resulted in failure. I know the reason that they won't work the same way is that my buttons are instantiated in other classes and not in the host class. What is the correct way to fix this error?
The method that doesn't work for reference:
public void OnClickSearch(View view) {
final Button button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText text = (EditText)findViewById(R.id.editText);
String value = text.getText().toString();
setContentView(R.layout.search_results);
}
});
}
It sounds like you are mis-understanding how the UI works in Android.
It is not normally expected that you will change an Activity's view on the fly as your are doing in your OnClickListener.
Instead, you should do one of two things. Either switch to a new Activity, using an Intent and the Activity's startActivity method, or use Fragments, and replace a Fragment in your Activity with a new Fragment.

Which context do i need?

I'm creating a dialog box and using the (this) isnt working. Up until now its just been a button calling a dialogbox but now the button within the called dialogbox needs to call another dialog. The Dialog dialogdelcon is the one with problem.
Here is the code:
case R.id.delappt:
//rmvall();
final Dialog dialogdelsel = new Dialog(this);
dialogdelsel.setContentView(R.layout.delsel);
dialogdelsel.setTitle("What would you like to do?");
dialogdelsel.setCancelable(true);
Button btndelsel = (Button) dialogdelsel.findViewById(R.id.btndelsel);
btndelsel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// delete selected code here.
}
});
Button btndelall = (Button) dialogdelsel.findViewById(R.id.btndelall);
btndelall.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// delete all code here.
final Dialog dialogdelcon = new Dialog();
dialogdelcon.setContentView(R.layout.delcon);
dialogdelcon.setTitle("Deletion Confirmation");
dialogdelcon.setCancelable(true);
Button buttoncnclok = (Button) dialogdelcon.findViewById(R.id.btndelcon);
buttoncnclok.setOnClickListener(new OnClickListener() {
// on click for cancel button
#Override
public void onClick(View v) {
dialogdelcon.dismiss();
}
});
dialogdelcon.show();
}
});
dialogdelsel.show();
break;
getApplicationContext() or use YourActictyName.this Because this refers the button click listner ,not your class Object
If this code is in the onCreate() method, or similiar, add getApplicationContext() instead of this and you should be fine. That's because this in a Button-context will refer to the button environment.
To improve the isolation between the two dialogs, it would be best to call showDialog(R.id.delapptcon) from the onClick handler. Then load the new dialog in the onCreateDialog of your activity. In this way, you can create more reusable dialogs and avoid the scoping issue you have now.

Categories

Resources