更改为片段后,启动活动不起作用

时间:2014-01-06 23:57:02

标签: android android-activity

我正在使用start activity

调用另一个活动

我将第二个活动改为碎片。现在我使用start activity

调用此片段时有异常 请帮忙。

Intent intentToOrder = new Intent(Food_Profile.this,
                            OrderMeal.class);
                    startActivity(intentToOrder);

请注意OrderMeal是片段

            tv_orderMeal.setOnTouchListener(new OnTouchListener(){

public boolean onTouch(View v, MotionEvent event) {
                if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                    // down
                    tv_orderMeal.setCompoundDrawablesWithIntrinsicBounds(0,
                            R.drawable.order_clicked, 0, 0);
                } else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
                    tv_orderMeal.setCompoundDrawablesWithIntrinsicBounds(0,
                            R.drawable.order, 0, 0);
                    Basket.setRestaurant(restaurant);
                    List<OrderFood> foodsToOrder = new LinkedList<OrderFood>();
                    OrderFood oneFoodOrder = new OrderFood();
                    oneFoodOrder.setRestaurantFood(restaurantFood);
                    oneFoodOrder.setNumber(1);
                    foodsToOrder.add(oneFoodOrder);
                    Basket.setFoods(foodsToOrder);
                    Intent intentToOrder = new Intent(Food_Profile.this,
                            OrderMeal.class);
                    startActivity(intentToOrder);
                    // up
                }
                return true;
            }
        });

1 个答案:

答案 0 :(得分:0)

试试这个:

Intent intentToOrder = new Intent(getActivity(),OrderMeal.class);
startActivity(intentToOrder);