i’m using actionbar sherlock/fragments with my app
my problem is that i need to call a async task to run in the fragment which is a static class
the complier is complaining about “No enclosing instance of type KeywordSearch is accessible”
i’ve thought of moving the async class out and create it’s own class, but there are too many variables declared in my KeywordSearch class that is used in the async task
how can i execute the async task without crashing?
my list view class(fragment):
public static class ListFragment extends Fragment {
private ListView list_list;
private LazyAdapter adp_list;
private KeywordSearch.SearchTask run;
//run.execute();
//new SearchTask().execute();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onDestroy()
{
if(!RTN_REQ.equals("SSDR") && data_got){
adp_list.imageLoader.stopThread();
}
list_list.setAdapter(null);
if(data_got)
ImageLoader.clearCache(true,true);
super.onDestroy();
}
@Override
public void onPause()
{
/*
if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
list_list.setNumColumns(2);
}else if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
list_list.setNumColumns(3);
}
*/
super.onPause();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.list, container, false);
adp_list = new LazyAdapter(getActivity(),list_data, 0);
run = new SearchTask();
list_list = (ListView) v.findViewById (R.id.list);
if(list_data != null){
list_list.setAdapter(adp_list);
list_list.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String[] FINAL = list_data[arg2].split("##");
final Intent d = new Intent();
d.putExtra("DATA",FINAL[0]);
d.setClass(getActivity().getApplicationContext(), Details.class);
startActivity(d);
return false;
}
});
list_list.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
if(!eno_act){
String[] FINAL = list_data[arg2].split("##");
final Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(FINAL[1]));
startActivity(i);
}else{
String[] FINAL = list_data[arg2].split("##");
level = 1;
level_filter = FINAL[2];
run.execute(); //this is where it crashes!!
}
}
});
}
return v;
}
}
and my SearchTask class:
class SearchTask extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
//....to long to show..
}
@Override
protected String doInBackground(Void... unsued) {
//....to long to show..
}
@Override
protected void onProgressUpdate(Void... unsued) {
//....to long to show..
}
@Override
protected void onPostExecute(String sResponse) {
//....to long to show..
}
}
Pass those variables of your KeyWordSearch class in constructor of async task class
for example
For passing data example
//in your async task you can do that in doInBackground or any other method.
Let foo is your string array
// Receive this array in your activity as