Reputation: 79
How to call from public static void to not static public void in Fragment class? Or is there another way to call between (listViewHolder.dot.setOnClickListener(new View.OnClickListener() and public void search3() )
// Tab2
// public class Tab2 extends Fragment
public void search3() {
Toast.makeText( getActivity(),"search3333333: " ,Toast.LENGTH_SHORT ).show();
}
public static void search4 (Context context1,String text) {
Toast.makeText( context1,text,Toast.LENGTH_LONG ).show();
Tab2 someClass = new Tab2();
someClass.search3();
}
//CustomAdapter
//public class CustomAdapter extends BaseAdapter
listViewHolder.dot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText( context,"" + ff.getText().toString() ,Toast.LENGTH_LONG).show();
Tab2.search4(context,"hi hhhh");
}
});
Upvotes: 0
Views: 486
Reputation: 79
put public class CustomAdapter extends BaseAdapter inside tab2 Fragment class like this way class CustomAdapter extends BaseAdapter and remove static
Thank you very much to all
Upvotes: 0
Reputation: 23788
If you want to call Fragment
or Activity
method from your OnClickListener
, you have to store a reference to that Fragment
or Activity
somewhere. Probably something like this will work for you:
public class CustomAdapter extends BaseAdapter {
private final Tab2 tab2;
// other fields
public CustomAdapter(Tab2 tab2, /* other constructor params ... */ ) {
this.tab2 = tab2;
// process other params and other initialization
}
...
@Override
public View getView (int position, View convertView, ViewGroup parent) {
...
listViewHolder.dot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tab2.search3();
}
});
...
}
}
Upvotes: 0