-1
我有一個佈局,像這樣:爲什麼在嘗試從一個片段向另一個片段發送數據時出現此錯誤?
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了錯誤,但找不到解決我的問題的任何東西。
請張貼PersonStats'的'代碼。 – Rohit5k2
getActivity後的括號括起來 –
@ Rohit5k2我添加了PersonStats的所有代碼。 – Brian