Currently I have Project A (as Android Library) and Project B.
In Project B I am using page fragment for the design. At page fragment 1, the fragment is actually called from Project A (the library).
How do i receive the onclick value on Project A to Project B.
// Declare the fragment page on Project B
CustFragment fragment1 = new CustFragment ();
// onclick listener on Project A
mContactList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Cursor cursor = (Cursor) parent.getAdapter().getItem(position);
long rawId = cursor.getLong(cursor
.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID));
// how do i pass the value to B?
}
EDITED: I edited this post with more code from my side
// Declare the fragment on Project B
public class MainPagerFragmentAdapter extends FragmentPagerAdapter {
ListFragment list;
SearchFragment search;
public MainPagerFragmentAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public int getCount() {
return 2;
}
public String getPageTitle(int position) {
switch (position) {
case 0: return AppSingleton.getCurrentActivity().getString(R.string.pager_appointments_tab);
case 1: return AppSingleton.getCurrentActivity().getString(R.string.explist_filter_text);
}
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
if (customerList == null)
list = new ListFragment();
return customerList;
case 1:
if (contactSearch == null)
search = new SearchFragment();
return contactSearch;
}
return null;
}
}
// onclick listener on Project A (library project)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
log.info("ContactsFragment onCreateView");
mContactFragmentView = inflater.inflate(R.layout.fragment_contacts,
container, false);
mContactList = (ListView) mContactFragmentView
.findViewById(R.id.contacts_list);
mContactList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Cursor cursor = (Cursor) parent.getAdapter().getItem(position);
long rawId = cursor.getLong(cursor
.getColumnIndex(ContactsContract.Data.RAW_CONTACT_ID));
// what have to done here to pass back to B dynamically
}
});
getLoaderManager().initLoader(0, null, this);
return mContactFragmentView;
}
- java.lang.NullPointerException at com.contact.library.ContactsFragment$2.onItemClick(ContactsFragment.java:143) at android.widget.AdapterView.performItemClick(AdapterView.java:308) at android.widget.AbsListView.performItemClick(AbsListView.java:1509) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3467) at android.widget.AbsListView$3.run(AbsListView.java:4830) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5602) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method)