在适配器中创建接口,并将其传递到适配器的构造函数中
class MyAdapter extends baseAdapter { public interface IProcessFilter { void onProcessFilter(String string1, String string2) } private IProcessFilter mCallback; public MyAdapter(Context context, String string1, String string2, IProcessFilter callback) { mCallback = callback; } public View getView( final int position, View convertView, ViewGroup parent) { holder.checkBox.setonClickListener( new View.onClickListener() { public void onClick(View v) { mCallback.onProcessFilter("string1", "string2"); } } }}
最后一件事,像这样在片段中实现它
public class MyFragment extends Fragment implements IProcessFilter { ... ... @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.my_fragment_layout, container, false); no_of_filter = (TextView) view.findViewById(R.id.no_of_filter_tv); MyAdapter custom_adapter = new MyAdapter(context, "string 1", "string 2", this); } @Override public void onProcessFilter(String string1, String string2) { // Process the filter }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)