Android : pass context of activity in AdapterView.OnItemClickListener(){} nested in fragment - The method is undefined

on Sunday, September 21, 2014


I have a problem with pass the context of activity in this method



private void registerClicksOnParents(ListView listView, final Dialog d, final
ImageButton btn, final ChildAndActivityDataClass currentChild) {
listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

d.dismiss();
btn.setImageResource(R.drawable.odebrany);
btn.setEnabled(false);
currentChild.setOdbiorDzieckaIdOfState(App_class.odebrane);
SingleInfoToServer singleInfoToServer = SingleInfoToServer(currentChild.getIdOfChild(),
currentChild.getOdbiorDzieckaIdOfActivity(),
currentChild.getOdbiorDzieckaIdOfState(),
context);
}
});


}


When I invoke this method in onItemClick I can't use getActivity, I try with, MainScreen.this but nothing works. I try to get context in Fragment onCreate method this way:



public class Aktywnosci_Fragment extends Fragment {

Context context ;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
context = getActivity();

}


but it stills shows the same The method SingleInfoToServer(int, int, int, Context) is undefined for the type new AdapterView.OnItemClickListener(){}


This method constructor looks like this



public SingleInfoToServer( int idOfChild, int idOfActivity, int idOfState, Context context)
{
this.context = context;
this.idOfChild = idOfChild;
this.idOfActivity = idOfActivity;
this.idOfState = idOfState;
}


so everything should works


0 comments:

Post a Comment