0

I am trying to get onItemClick on ListItems to work from a fragment. It complains to remove @Override method ..here is my code which is in a fragment class extends my Other fragment

ListView listView = (ListView) getView().findViewById(R.id.listView);
adapter = new ArrayAdapter<NewsItem>    
(getActivity(),android.R.layout.simple_list_item_1,newsItemsList);
setListAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent myIntent = new Intent(view.getContext(), NewsSummaryActivity.class);
    startActivity(myIntent);
}
});
Tameem Ahmed
  • 71
  • 1
  • 2
  • 7

3 Answers3

3

You are using the JRE 1.5 compiler settings, where using @Override like this is an error. The code sample you are trying to copy uses JRE 1.6, where it is an error to not use @Override.

Either

  • Remove the @Override since you cannot use it here in 1.5 or
  • Change your compiler version with:

    Project -> Properties -> Java Compiler -> Java Compliance Level

Sam
  • 86,580
  • 20
  • 181
  • 179
  • `@Override` exists in Java 1.5, just not for interfaces. – Cat Dec 05 '12 at 22:37
  • Good point, I changed the language around to make it clearer. (Upvote for having the same basic answer and the link you found.) – Sam Dec 05 '12 at 22:44
  • 1
    (+1 For you also now that it's a bit clearer. Seems we end up doing this a lot... :P) – Cat Dec 05 '12 at 22:45
  • Do you read at lightning fast rates or was that a co-incidence? – Sam Dec 05 '12 at 22:45
  • Both, probably. Happened to have this open as soon as you edited it. :) – Cat Dec 05 '12 at 22:45
1

Just remove the @Override. Some compiler levels (below 1.6, I think) complain when you have @Override on interface methods. It will not affect functionality in any way to remove that.

For a far more detailed explanation: When do you use Java's @Override annotation and why?

Community
  • 1
  • 1
Cat
  • 66,919
  • 24
  • 133
  • 141
0

Just Go to the Simple Way......

In your Adapter Class... between getView method... put View v = convertView; and just set listener on it.

enter code herev.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(context, "Name : "+ list.get(position).getS_name(), Toast.LENGTH_SHORT).show();
        }
    });`

'I hope this will help you.....'

suraj
  • 641
  • 1
  • 7
  • 15