I know there are some topics in StackOverFlow asking this But all of them are answering in special cases No one answers this question generally.
Can anyone say how to use findViewById in non activity classes?
For Example in my case I want to define a webview:
WebView view=(WebView)findViewById(R.id.webview);
But I can't and I really don't understand why android makes everything complicated.Why you can use everything in main activity but you can't use many of them in non activity class :(
UPDATE
I can't extend my class as activity cause it extends sth else.
UPDATE
This is the class:
class DownloadTask extends AsyncTask<String, Void, Void> {
protected Void doInBackground(String... sUrl) {
...
WebView view=(WebView)findViewById(R.id.webview);
final Snackbar snackbar = Snackbar.make(view,"message",Snackbar.LENGTH_LONG);
...
}
}
I'm gonna use the webview in a Snackbar.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…