尝试将数据从一个片段发送到另一个片段时,为什么会出现此错误?

时间:2016-02-03 19:16:15

标签: android android-fragments

我有这样的布局:

person_stats.xml

<LinearLayout>
    <ListView android:id="@+id/row_of_information"></ListView>
</LinearLayout>

此ListView由游标适配器填充,如下所示:

PersonStats.java

public class PersonStats extends Fragment {
    private View rootView;
    private DatabaseHelper myDBHelper;
    private Cursor dataCursor;
    private SimpleCursorAdapter mySimpleCursorAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        rootView = inflater.inflate(R.lalyout.person_stats, container, false);
        myDBHelper = new DatabaseHelper(getActivity());

        dataCursor = myDBHelper.getDataCursor();
        String fromColumns = {"_id","home_address","home_phone", ...};
        int[] toViews = {R.id.home_address, R.id.home_phone, ...};
        mySimpleCursorAdapter = new SimpleCursorAdapter(getActivity(), R.layout.person_layout, dataCursor, fromColumns, toViews, 0);
        ListView myListView = (ListView) findViewById(R.id.row_of_information);
        myListView.setAdapter(mySimpleCursorAdapter);

        return rootView;
    }
}

行布局:

person_layout.xml

<LinearLayout>
    <TextView />
    <TextView />
    <TextView />
    <TextView />
</LinearLayout>

但是,当我尝试将数据发送到此片段时,如下所示:

PersonStats personStats = new PersonStats();
Bundle myBundle = new Bundle();
myBundle.putString("home_address", home_address);
personStats.setArguments(myBundle);
getFragmentManager().beginTransaction().add(R.id.row_of_information, personStats).commit();

我总是得到错误:

UnsupportedOperationException addView(View) is not supported in AdapterView

我用Google搜索了错误,但无法找到解决问题的任何内容。

1 个答案:

答案 0 :(得分:0)

这是您应该使用的签名。请更新方法签名。

 std::vector<cv::Point2d> projectedPoints;

请参阅this