I have 3 errors in the code of notification using OnItemClickListener
i need to apply that when an item is clicked it display notification
here is the code:
list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
Bundle programNum = getIntent().getExtras();
final String progNum = programNum.getString("ProgNum");
final String dayNum = programNum.getString("DayNum");
final List<TouringPrograms> startTime = datasource.getTouringProgramsStartTime(progNum, dayNum);
final List<TouringPrograms> endTime = datasource.getTouringProgramsEndTime(progNum, dayNum);
Intent intent = new Intent(this, ProgramsList2.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
String body = (String) ((TextView)parent.getChildAt(position)).getText();
String title = "Egypt On The Go";
String time = body + "\n start at:" + startTime.get(position)+ "\n end at:" + endTime.get(position);
Notification n = new Notification(R.drawable.egypt, time, System.currentTimeMillis());
n.setLatestEventInfo(this, title, time, pi);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniqueID, n);
//String time1 = "" + System.currentTimeMillis();
//Toast.makeText(this, time1, Toast.LENGTH_SHORT).show();
//finish();
}});
the 3 error :
1.Intent intent = new Intent(this, ProgramsList2.class);
2.PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
3.n.setLatestEventInfo(this, title, time, pi);
any help please?
Error 1
thisis an item of typeOnItemClickListener. You should pass it by declaringfinal Context intentContext = (Context) this;before callingsetOnItemClickListener. Then, use:Always remember to keep track of your
Contextitems; they’re important for things like this (Intents, resources, assets, etc.).Error 2
Exactly the same problem as above.
thisis not of typeContext. Use the same fix as above.Error 3
And here, same issue as the above two. You’re using
thiswhen you should be using aContext. Same fix as the above two.Summary
Keep track of your
thiss when using anonymous classes. And for the future, posting the compile errors (the line of code as well as the text of the error itself) is incredibly helpful to those who will provide answers.