How do you run a method from the OnClick of a list item?
My method is called CallEmergency()
public void CallEmergency(View arg0) {
String phone_no = "911";
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phone_no));
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(callIntent);
}
I can start other activities with:
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent i = new Intent(getApplicationContext(), Activity.class);
startActivity(i);}
but I’d like to just run this CallEmergency() method.
Simply use:
(Please read about Java naming conventions, which state that methods like
callEmergency()should start with lower case letter.)