title: Can't start Activity from OnClickListener "method startActivity(Intent, int) is undefined for the type"
body: <p>I am populating a Scrollview using items retrieved from a SQLite database, and am dynamically generating an OnClickListener for each row using the code below. I want the code in the OnClickListener to return control to the Activity which called it (MealActivity) using an Intent, passing back the id of the item which was clicked on. </p>
  
  <p>I've attempted this using the 2nd code segment below, but I'm getting a compile error: "The method startActivity(Intent, int) is undefined for the type OnClickListenerSelectPresetItem".</p>
  
  <p>How can I invoke the original Activity from my OnClickListener?</p>
  
  <pre><code>public class SelectPresetItemActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_select_preset_item);
  
          if (savedInstanceState == null) {
              getFragmentManager().beginTransaction()
                      .add(R.id.container, new PlaceholderFragment()).commit();
          }
  
          readRecords();
      }
  
      public void readRecords() {
          LinearLayout linearLayoutRecords = (LinearLayout) findViewById(R.id.linearLayoutRecords);
          linearLayoutRecords.removeAllViews();
  
          List&lt;preset_item&gt; preset_item = new TableControllerPresetItem(this).read();
  
          if (preset_item.size() &gt; 0) {
  
              for (preset_item obj : preset_item) {
  
                  long id = obj.id;
                  String PresetDesc = obj.preset_desc;
                  int PresetMinutes = obj.preset_minutes;
  
                  String textViewContents = PresetDesc + " - "
                          + PresetMinutes + " minutes";
  
                  TextView textViewItem = new TextView(this);
                  textViewItem.setPadding(0, 10, 0, 10);
                  textViewItem.setText(textViewContents);
                  textViewItem.setTag(Long.toString(id));
  
                  textViewItem.setOnClickListener(new OnClickListenerSelectPresetItem());
  
                  linearLayoutRecords.addView(textViewItem);
              }
  
          }
  
          else {
  
              TextView locationItem = new TextView(this);
              locationItem.setPadding(8, 8, 8, 8);
              locationItem.setText("No records yet.");
  
              linearLayoutRecords.addView(locationItem);
          }
      }listener
  
  The method startActivity(Intent, int) is undefined for the type OnClickListenerSelectPresetItem
  
  
      public class SelectPresetItemActivity extends Activity {
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_select_preset_item);
  
              if (savedInstanceState == null) {
                  getFragmentManager().beginTransaction()
                          .add(R.id.container, new PlaceholderFragment()).commit();
              }
  
              readRecords();
          }
  
          public void readRecords() {
              LinearLayout linearLayoutRecords = (LinearLayout) findViewById(R.id.linearLayoutRecords);
              linearLayoutRecords.removeAllViews();
  
              List&lt;preset_item&gt; preset_item = new TableControllerPresetItem(this).read();
  
              if (preset_item.size() &gt; 0) {
  
                  for (preset_item obj : preset_item) {
  
                      long id = obj.id;
                      String PresetDesc = obj.preset_desc;
                      int PresetMinutes = obj.preset_minutes;
  
                      String textViewContents = PresetDesc + " - "
                              + PresetMinutes + " minutes";
  
                      TextView textViewItem = new TextView(this);
                      textViewItem.setPadding(0, 10, 0, 10);
                      textViewItem.setText(textViewContents);
                      textViewItem.setTag(Long.toString(id));
  
                      textViewItem.setOnClickListener(new OnClickListenerSelectPresetItem());
  
                      linearLayoutRecords.addView(textViewItem);
                  }
  
              }
  
              else {
  
                  TextView locationItem = new TextView(this);
                  locationItem.setPadding(8, 8, 8, 8);
                  locationItem.setText("No records yet.");
  
                  linearLayoutRecords.addView(locationItem);
              }
          }
  </code></pre>
  
  <p>This is the OnCLickListener code:</p>
  
  <pre><code>public class OnClickListenerSelectPresetItem implements OnClickListener {
      public final static String EXTRA_MEAL_ID = "com.ian.mealtimer.MEAL_ID";
  
      @Override
      public void onClick(View view) {
  
          Long selectedMealId = Long.valueOf(view.getTag().toString());
          Intent myIntent = new Intent(view.getContext(),
                  MealActivity.class);
          long mealId = -1;
          myIntent.putExtra(EXTRA_MEAL_ID, selectedMealId);
          startActivity(myIntent, 0);
  
      }
  }
  </code></pre>