Reputation: 71
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);
}
});
Upvotes: 0
Views: 3708
Reputation: 641
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 here
v.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.....'
Upvotes: 0
Reputation: 86948
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
@Override
since you cannot use it here in 1.5 or Change your compiler version with:
Project -> Properties -> Java Compiler -> Java Compliance Level
Upvotes: 3
Reputation: 67502
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?
Upvotes: 1