0

how to start new activity in baseadapter i do the default way to open activity but not work with baseadapter

Intent intent = new Intent(context,AnotherActivity.class); context.startActivity(intent);

 @Override
public View getView(final int p, View convertView, ViewGroup parent) {
    View grid;
    LayoutInflater inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {

        grid = new View(mContext);
        grid = inflater.inflate(R.layout.gridview_custom_layout, null);

    } else {
        grid = (View) convertView;
    }
    TextView textView = (TextView) grid.findViewById(R.id.gridview_text);
    ImageView imageView = (ImageView)grid.findViewById(R.id.gridview_image);
    textView.setText(string[p]);
    imageView.setImageResource(Imageid[p]);

    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (p){
                case 0:
                    Toast.makeText(v.getContext(), "Clicked Laugh Vote", Toast.LENGTH_SHORT).show();
                    break;
                case 1:
                    Toast.makeText(v.getContext(), "2", Toast.LENGTH_SHORT).show();
                    break;
                case 2:

                    break;
                default:
                    // Do something else
                    break;
            }
        }
    });
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0
Intent yourIntent = new Intent(mContext,Wukong.class);
                    yourIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                   mContext.startActivity(yourIntent);
Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
0

You can use the following code to start a new Activity BaseAdapter:

imageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        mContext.startActivity(new Intent(mContext,YourActivity.class))
    }
});
Grant Miller
  • 27,532
  • 16
  • 147
  • 165
Akash
  • 961
  • 6
  • 15
  • While this code may answer the question, it is better to explain how to solve the problem and provide the code as an example or reference. Code-only answers can be confusing and lack context. – Robert Columbia Aug 21 '18 at 22:34