0

Hello I want to make a click listener in a sherlockfragment but every time I click it, it displays "view.class source not found" it doesn't matter what action I do I want to use it to start an intent to change an activity

here is my code:

public class SafanTab extends SherlockFragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    return inflater.inflate(R.layout.safantab, container, false);

}

public void onOverClick(View view) {
    Intent myIntent = new Intent(view.getContext(), OverSafan.class);
    startActivityForResult(myIntent, 0);
    }


public void nProductenClick(View view) {
    Intent myIntent = new Intent(view.getContext(), Over_Safan.class);
    startActivityForResult(myIntent, 0);
    }


public void onTwitterClick(View view) {
    Intent myIntent = new Intent(view.getContext(), Over_Safan.class);
    startActivityForResult(myIntent, 0);
    }

}

I define the listener to the button in the layout xml:

android:onClick="OnOverClick"

I tried it a long time and also searched the internet for "View.class source not found" but can't find anything to solve my problem. As you see in the question I'm using ActionBarSherlock.

vinay kumar
  • 1,451
  • 13
  • 33
user1534326
  • 115
  • 1
  • 2
  • 6
  • This is only a debug message saying that Eclipse couldn't find the source for View.class (which is part of the Android OS classes). Try finding the problem prior to that by placing breakpoints in your code and seeing if the event is caught correctly. – IncrediApp Aug 02 '12 at 12:49
  • Im very new to devoleping are breakepoints "try & else"? – user1534326 Aug 02 '12 at 12:58
  • According to what you wrote, I assume you run your app in debug mode (you click on the debug icon or on Debug as -> Android application). Breakpoints are places in the code where you want to stop and inspect that current state of your objects. To place one in Eclipse, simply click on the left border right next to the line of code – IncrediApp Aug 02 '12 at 13:07

2 Answers2

2

You won't get the onOverClick callback in the fragment. Use something like the following in your onActivityCreated() method.

    // Handle onclick
    getView().findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // do something
        }
     });

See this question for more options: How to handle button clicks using the XML onClick within Fragments

EDIT: For onCreateView you can do the following:

  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     View view = inflater.inflate(R.layout.my_layout, container, false);
     view.findViewById(R.id.button1).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // do something
        }
     });
     return view;
  }
Community
  • 1
  • 1
Frohnzie
  • 3,559
  • 1
  • 21
  • 24
  • If i place in it in the "onCreateView" method i get just source not found can you maybe tell where can must put your code in mine code? I think im pretty close to the answer now :) – user1534326 Aug 02 '12 at 13:23
  • I place the code in onActivityCreated. Basically any time after onCreateView is called. I will update my answer. http://developer.android.com/guide/components/fragments.html#Creating – Frohnzie Aug 02 '12 at 13:28
  • If i place it i need after the } from the onClick method place ); or it will give an error when i place en debug this it gives source not found – user1534326 Aug 02 '12 at 13:37
  • did you remove `android:onClick="OnOverClick"` from the XML. Otherwise I am not sure what other issues your are having. – Frohnzie Aug 02 '12 at 13:52
  • i debugged it again and now i get "DexFile.class source not found" – user1534326 Aug 02 '12 at 14:01
  • But why for dexfile attach the source and for the view.class not? – user1534326 Aug 02 '12 at 14:14
-1

Not sure if this is the problem, but I see that the name of your method is defined as:

public void onOverClick(View view)

but in the XML you specify:

android:onClick="OnOverClick"

Letter "O" is capitalized in xml.

Andy Res
  • 15,963
  • 5
  • 60
  • 96