我想从companyName
班级到fragment
班级Adapter
这是我的适配器类
@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");
现在,我需要在此
companyName
课程中使用此fragment
来访问Adapter
有人可以告诉我该怎么做。
**This Question is complete edit**
答案 0 :(得分:3)
在将数据发送到片段之前,您已经替换了片段。您的代码序列应为
String toDeliveryList=getIntent().getStringExtra("userName");
Bundle bundle=new Bundle();
bundle.putString("userID",toDeliveryList);
DeliveryList dl=new DeliveryList();
dl.setArguments(bundle);
fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_container, d1);
fragmentTransaction.commit();
是的,不要忘记将new DeliveryList()
替换为d1
中的fragmentTransaction.replace()