接口回調


//適配器中ide

   //定義一個接口
    public interface Onand {
        void shouText(Integer poss);
    }this

    //聲明接口變量
    public Onand onand;.net

    //提供方法,暴露接口
    public void setOnand(Onand onand) {
        this.onand = onand;
    }接口


//條目點擊事件
    llcont = (LinearLayout) itemView.findViewById(R.id.llcont);
    llcont.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
         onand.shouText(getLayoutPosition());
       }
    });事件

//-----------------------------------------------------    
//Activtiy或者Fragment中get

    //接口回調         
    adapter.setOnand(new MyAdapter.Onand() {
        @Override
        public void shouText(Integer poss) {
    //吐司
               Toast.makeText(getActivity(), list1.get(poss).getData().getSummary(), Toast.LENGTH_SHORT).show();
              }
        });it

相關文章
相關標籤/搜索