如何将数据从片段传递到适配器类?

时间:2017-09-02 19:15:00

标签: android

  

我的值companyNameMyfragment课程中我需要将此companyName值传递给MyAdapter课程。并且没有从Myfragment移动到MyAdapter活动。有人可以告诉我该怎么办?我对其他网站上的每场比赛感到困惑。

这是我的适配器类

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d("test",""+deliveryListBeans.size());
LayoutInflater inflater=(LayoutInflater)ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v=inflater.inflate(R.layout.list_view_for_delivery_list,null);
Button delivered=(Button)v.findViewById(R.id.do_delivered);
delivered.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent deliveryUpdate=new Intent(ct, MyOwn.class);
        deliveryUpdate.putExtra("invoiceId",dlb.getInvoiceNo());
        ct.startActivity(deliveryUpdate);
    }
});
return v;

}

  

setOnClickListener我需要来自companyName类的fragment值,以便我可以在网址中使用它。

这是我的片段类

public class DeliveryList extends Fragment {
private List<DeliveryListBean> dlblistbean= new ArrayList<DeliveryListBean>();
ListView listview;
Button delivered;
String companyName;}
 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                     Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View rootView = inflater.inflate(R.layout.fragment_delivery_list,container,false);
listview=(ListView) rootView.findViewById(R.id.deliveryListView);
companyName=this.getArguments().getString("companyName");
listview.setAdapter(deliveryListAdapter);
return rootView;
}

1 个答案:

答案 0 :(得分:0)

在您的适配器类

public class MyAdapter {

    private Context mContext;
    private String mCompanyName;

    public MyAdapter(Context context, String companyName) {
        mContext = context;
        mCompanyName = companyName;
    }
}