开关(机箱)不工作

时间:2016-05-29 13:24:25

标签: android arrays grid switch-statement

我正在使用switch语句来使用所选用户的图像并将其作为背景图像。

但案件不起作用(案例0除外)

这是发送数据(位置)意图

//初始化视图

    DetailFruit imageAdapterf = new DetailFruit(this);
    DetailVegetable imageAdapterv = new DetailVegetable(this);

    // Get intent data from home for the category
    Intent i = getIntent();
    // Selected image id
    position = i.getExtras().getInt("id");

    // Getting data from Detail activity for the food
    // Get intent data from detail
    Intent in = getIntent();
    // Selected image id
    positions = in.getExtras().getInt("ids");

    // setting the background image which the user is selected
    switch (position){
        case 0:
            singleimage.setImageResource(imageAdapterf.fruits[positions]);
            break;
        case 1:
            singleimage.setImageResource(imageAdapterv.vegetable[positions]);
            break;
        default :
            Toast.makeText(SingleActivity.this, "default", Toast.LENGTH_SHORT).show();
            break;
    }

这是接收的Intent数据(位置)

background-image

0 个答案:

没有答案