Note that there are some explanatory texts on larger screens.

plurals
  1. POClassCastException while setting callback for customView from Fragment
    primarykey
    data
    text
    <p>I am trying to receive a CallBack in MyCustomView which is a class representing a Fragment( or we can say, it is view for Fragment) when i hit any element in ListFragment. Logs are attached Below:</p> <pre><code>04-12 11:56:04.321: D/FirstFragment(762): setting ui listener callback 04-12 11:56:04.321: D/AndroidRuntime(762): Shutting down VM 04-12 11:56:04.321: W/dalvikvm(762): threadid=1: thread exiting with uncaught exception (group=0x40015560) 04-12 11:56:04.331: E/AndroidRuntime(762): FATAL EXCEPTION: main 04-12 11:56:04.331: E/AndroidRuntime(762): java.lang.ClassCastException: com.gaurav.listing.ListFragmentActivity 04-12 11:56:04.331: E/AndroidRuntime(762): at com.gaurav.listing.FirstFragment.onListItemClick(FirstFragment.java:66) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.widget.ListView.performItemClick(ListView.java:3513) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.os.Handler.handleCallback(Handler.java:587) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.os.Handler.dispatchMessage(Handler.java:92) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.os.Looper.loop(Looper.java:123) 04-12 11:56:04.331: E/AndroidRuntime(762): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-12 11:56:04.331: E/AndroidRuntime(762): at java.lang.reflect.Method.invokeNative(Native Method) 04-12 11:56:04.331: E/AndroidRuntime(762): at java.lang.reflect.Method.invoke(Method.java:507) 04-12 11:56:04.331: E/AndroidRuntime(762): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-12 11:56:04.331: E/AndroidRuntime(762): at 04-12 11:56:04.331: E/AndroidRuntime(762): at dalvik.system.NativeStart.main(Native Method)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) </code></pre> <p>and following i am attaching the Fragment's piece of code from where i am trying to set up this call back.</p> <pre><code>package com.gaurav.listing; import android.app.Activity; public class FirstFragment extends ListFragment { private static final String TAG = "FirstFragment"; public UIListener uiCallback; ArrayAdapter adapter; ListView list; View view; String[] values; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // some code here... } @Override public void onResume() { // some code here... } Activity activity = null; @Override public void onAttach(Activity activity) { super.onAttach(activity); try { this.activity = activity; uiCallback = (UIListener) activity; } catch (ClassCastException e) { } } @Override public void onListItemClick(ListView l, View v, int position, long id) { Log.d("FirstFragment", "onListItemClick"); String shape = l.getItemAtPosition(position).toString(); Log.d(TAG, shape); if (null == uiCallback) { Log.d("FirstFragment", "setting ui listener callback"); // problem occur here uiCallback = (UIListener) activity; } uiCallback.onButtonClicked(l, v, position, id, shape); } } </code></pre> <p>Please let me know how can i fix this problem. Some more details regarding target where i want to receive the callback: id of fragment: second_fragment view class for fragment: SecondFragment.java</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload