[英]Eclipse doesn't recognize my class as a Fragment
我正在尝试将Fragment实例化为FragmenteActivity类,但是Eclipse不允许我这样做!
让我演示给你看:
那是我的片段类:
public class VendorListFragment extends Fragment {
private VendorListAdapter adapter;
private ArrayList<Vendor> vendorList;
private VendorSQLiteHelper dbHelper;
private ListView listView;
public VendorListFragment() {
// empty constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_vendor_list, container, false);
listView = (ListView) rootView.findViewById(R.id.listView);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
this.setRetainInstance(true);
return rootView;
}
这样您就可以看到它扩展了Fragment,对吗? 但是在我的FragmentActivity类中,当我编写代码时
fragmentTransaction.add(R.id.view_trade_show_vendor_fragment, new VendorListFragment());
Eclipse说:
FragmentTransaction类型的方法add(int,Fragment)不适用于参数(int,VendorListFragment)
因此,即使使用扩展片段,Eclipse也不认为我的ViewTradeShowActivity是片段,怎么了?!
在下面查看更多代码:
public class ViewTradeShowActivity extends FragmentActivity {
TextView viewTradeShowName;
TradeShow tradeShow;
Fragment vendorFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_trade_show);
tradeShow = getIntent().getParcelableExtra("tradeShow");
viewTradeShowName = (TextView) findViewById(R.id.view_trade_show_name);
viewTradeShowName.setText(tradeShow.getName());
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.add(R.id.view_trade_show_vendor_fragment, new VendorListFragment());
}
}
谢谢!
您确定进口正确吗?
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.