I know this has been asked before but the solutions here are not helping. My problem exists in the getView method at the bottom of my ImageAndTextAdapter class. I am getting the following error when I create a new intent:
"The Constructor Intent(new View.OnClickListener(){} Class ) is undefined."
MenuCells exists and is also in the manifest file.
ImageAndTextAdapter.java
public class ImageAndTextAdapter extends ArrayAdapter<String> {
private LayoutInflater mInflater;
private String[] mStrings;
private TypedArray mIcons;
private int mViewResourceId;
public ImageAndTextAdapter(Context ctx, int viewResourceId,
String[] strings, TypedArray icons) {
super(ctx, viewResourceId, strings);
mInflater = (LayoutInflater)ctx.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mStrings = strings;
mIcons = icons;
mViewResourceId = viewResourceId;
}
@Override
public int getCount() {
return mStrings.length;
}
@Override
public String getItem(int position) {
return mStrings[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
ImageView iv = (ImageView)convertView.findViewById(R.id.option_icon);
iv.setImageDrawable(mIcons.getDrawable(position));
TextView tv = (TextView)convertView.findViewById(R.id.option_text);
tv.setText(mStrings[position]);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
****THE ERROR GETS THROWN AT THIS LINE****
Intent intent = new Intent(this, MenuCells.class);
intent.putExtra("CELL_NAME", mStrings[position]);
startActivity(intent);
}
});
return convertView;
}
}
MENU_CELLS.java
package com.laerdalsun;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MenuCells extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bundle extras = getIntent().getExtras();
if(extras!=null) {
String value = extras.getString("CELL_NAME");
}
}
}