I am new to Android development and am having trouble changing things. I am trying to change the actions from a method, but I get a cannot resolve method startActivity error message, and at the end of the parameter, Cannot resolve constructor 'Intent (...)' error. I found a question here with the same problem and tried to implement my answers in my program, but not joy.
Here is the code:
public void open301(View view) { startActivity(new Intent(CustomAdapter.this, ThreeZeroOne.class)); }
before considering the answers from the question related to the above code, they looked the same with the same errors:
public void open301(View view) { Intent openThree = new Intent(this,ThreeZeroOne.class); startActivity(openThree); }
Full code:
import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import android.content.Intent; public class CustomAdapter extends BaseAdapter { String[] result; Context context; int[] imageId; private static LayoutInflater inflater = null; public CustomAdapter(selectGame SelectGame, String[] prgmNameList, int[] prgmImages) { result = prgmNameList; context = SelectGame; this.imageId = prgmImages; inflater = (LayoutInflater) context.getSystemService(Context. LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { return result.length; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } public class Holder { TextView tv; ImageView img; } @Override public View getView(final int position, View convertView, ViewGroup parent) { Holder holder = new Holder(); View rowView; rowView = inflater.inflate(R.layout.game_selection, null); holder.tv = (TextView) rowView.findViewById(R.id.txt); holder.img = (ImageView) rowView.findViewById(R.id.img); holder.tv.setText(result[position]); holder.img.setImageResource(imageId[position]); rowView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, "Beginning game " + result[position], Toast.LENGTH_SHORT).show(); } }); return rowView; } public void open301(View view) { Intent openThree = new Intent(this,ThreeZeroOne.class); startActivity(openThree); }
}
android
COYG
source share