0
你可以給我一個從片段類到活動列表視圖的listview中傳遞項目的例子嗎?感謝如果有人幫助我謝謝!Android - 將數據從片段傳遞到活動?
你可以給我一個從片段類到活動列表視圖的listview中傳遞項目的例子嗎?感謝如果有人幫助我謝謝!Android - 將數據從片段傳遞到活動?
看看Android開發人員培訓網站。它有你問什麼的實現,是一個更好的答案:
http://developer.android.com/guide/components/fragments.html
public static class FragmentA extends ListFragment {
OnArticleSelectedListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnArticleSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener");
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Append the clicked item's row ID with the content provider Uri
Uri noteUri = ContentUris.withAppendedId(ArticleColumns.CONTENT_URI, id);
// Send the event and Uri to the host activity
mListener.onArticleSelected(noteUri);
}
}