如何显示相关图片?

时间:2015-09-24 18:38:56

标签: android

我有三个Activity,第一个活动是List View,第二个是Expandable List,另一个是我想在它上面设置Image。 当我点击列表视图的第一项时,我转到可扩展列表,然后当我点击第一个父项的第一个孩子时,我进入最后的活动并设置书图像:

喜欢关注当我点击列表视图的第二项时,我会转到可扩展列表,然后当我点击第一位父母的第一个孩子时,我会进入最后的活动,但显示“上一页”图像:(:

任何人都可以告诉我如何完成以下任务:

“当我点击每个孩子时,显示相关图片”

列出活动代码:

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, final View view,
                int position, long id) {
            Intent i = new Intent(MainPage.this, MainActivity.class);
            i.putExtra("dars", position);
            startActivity(i);
        }

    });

expandableList活动代码:

        Intent nt = getIntent();
    int dars = nt.getIntExtra("dars", 0);
    switch (dars) {
    case 0:

        // Listview on child click listener
        expListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                switch (groupPosition) {
                case 0:
                    switch(childPosition){
                    case 0:
                        p = 0;
                        in = new Intent(MainActivity.this , SecondActivity.class);
                        in.putExtra("position", p);
                        startActivity(in);
                        break;
                    case 1:
                        p = 1;
                        in = new Intent(MainActivity.this , SecondActivity.class);
                        in.putExtra("position", p);
                        startActivity(in);
                        break;
                    case 2:
                        p = 2;
                        in = new Intent(MainActivity.this , SecondActivity.class);
                        in.putExtra("position", p);
                        startActivity(in);
                        break;

                    }
                    break;
                }
                return false;
            }
        });
    case 1:
        expListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                switch (groupPosition) {
                case 0:
                    switch(childPosition){
                    case 0:
                        s = 0;
                        in = new Intent(MainActivity.this , SecondActivity.class);
                        in.putExtra("ss", s);
                        startActivity(in);
                        break;
                    case 1:
                        s = 1;
                        in = new Intent(MainActivity.this , SecondActivity.class);
                        in.putExtra("ss", s);
                        startActivity(in);
                        break;
                    case 2:
                        s = 2;
                        in = new Intent(MainActivity.this , SecondActivity.class);
                        in.putExtra("ss", s);
                        startActivity(in);
                        break;

                    }
                    break;
                }
                return false;
            }
        });
        break;
    }
}

第三个活动代码:

        ImageView iv = (ImageView) findViewById(R.id.imageView1);

    Intent nt = getIntent();

    int pos = nt.getIntExtra("position", 0);

    switch (pos) {
    case 0:
        iv.setBackgroundResource(R.drawable.rhm1);
        break;
    case 1:
        iv.setBackgroundResource(R.drawable.rhm2);
        break;
    case 2:
        iv.setBackgroundResource(R.drawable.rhm3);
        break;
    }


    int ss = nt.getIntExtra("ss" , 0);

    switch (ss) {
    case 0:
        iv.setBackgroundResource(R.drawable.book);
        break;
    case 1:
        iv.setBackgroundResource(R.drawable.rhm5);
        break;
    case 2:
        iv.setBackgroundResource(R.drawable.rhm6);
        break;
    }

0 个答案:

没有答案