Issue
I am trying to call the view from another class in my Asynctask class but it doesn't seem to be working.
Here is my AsyncTack
private class parseSite extends AsyncTask<String, Void, List<Integer>> {
protected List<Integer> doInBackground(String... arg) {
List<Integer> output = new ArrayList<Integer>();
try {
htmlHelper hh = new htmlHelper(new URL(arg[0]));
output = hh.htmlHelper(arg[0]);
} catch (Exception e) {
System.out.println("Error");
}
return output;
}
protected void onPostExecute(List<Integer> exe) {
graph salesView = new graph();
View chartView = salesView.getView(this);
chartView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT, 1f));
LinearLayout layout = (LinearLayout) findViewById(R.id.linearview);
layout.addView(chartView, 0);
}
}
And here is what the activity 'graph' looks like
public class graph {
public View getView(Context context) (...etc.)
I don't understand why it can't call the view.
Solution
Assuming you intended graph
to extend Context
in some way, such as by extending Activity
, and that parseSite
is defined inside graph
, make the following change:
View chartView = salesView.getView(graph.this);
In the original code, this
is referring to parseSite
which does not extend Context
(and does not refer to graph
as you probably intend).
As a side note, in typical Java style classes should be named with an upper case letter, i.e. Graph
not graph
.
Answered By - Alex DiCarlo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.