0

所以我在三个选项卡之一中有一个列表视图。我将 SherlockListFragment 用于列表视图,它工作正常。我唯一迷失的就是如何将图像从字符串数组添加到列表视图。

这是列表视图的活动:

public class CurrentMobs extends SherlockListFragment{

    private static final int ACTIVITY_0 = 0;
    private static final int ACTIVITY_1 = 1; 
    private static final int ACTIVITY_2 = 2;
    private static final int ACTIVITY_3 = 3;
    private static final int ACTIVITY_4 = 4;
    private static final int ACTIVITY_5 = 5;
    private static final int ACTIVITY_6 = 6;
    private static final int ACTIVITY_7 = 7;
    private static final int ACTIVITY_8 = 8;
    private static final int ACTIVITY_9 = 9;
    private static final int ACTIVITY_10 = 10;
    private static final int ACTIVITY_11 = 11;
    private static final int ACTIVITY_12 = 12;
    private static final int ACTIVITY_13 = 13;
    private static final int ACTIVITY_14 = 14;
    private static final int ACTIVITY_15 = 15;
    private static final int ACTIVITY_16 = 16;
    private static final int ACTIVITY_17 = 17;
    private static final int ACTIVITY_18 = 18;
    private static final int ACTIVITY_19 = 19;
    private static final int ACTIVITY_20 = 20;

    @Override
      public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        String[] commands  = this.getResources().getStringArray(R.array.currentmobs_selections);
        String[] commandsImages = this.getResources().getStringArray(R.array.currentmobs_selections);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
            R.layout.main_list_item, commands);
        setListAdapter(adapter);
      }

      @Override
      public void onListItemClick(ListView l, View v, int position, long id) {
          super.onListItemClick(l, v, position, id);
            // Set up different intents based on the item clicked: 
            switch (position)
            {
            case ACTIVITY_0:
                Intent i = new Intent(getActivity(),Bat.class);
                startActivity(i);
                break;
            case ACTIVITY_1:
                Intent i1 = new Intent(getActivity(),Blaze.class);
                startActivity(i1);
                break;
            case ACTIVITY_2:
                Intent i2 = new Intent(getActivity(),CaveSpider.class);
                startActivity(i2);
                break;
            case ACTIVITY_3:
                Intent i3 = new Intent(getActivity(),Creeper.class);
                startActivity(i3);
                break;
            case ACTIVITY_4:
                Intent i4 = new Intent(getActivity(),EnderDragon.class);
                startActivity(i4);
                break;
            case ACTIVITY_5:
                Intent i5 = new Intent(getActivity(),Endermen.class);
                startActivity(i5);
                break;
            case ACTIVITY_6:
                Intent i6 = new Intent(getActivity(),Ghast.class);
                startActivity(i6);
                break;
            case ACTIVITY_7:
                Intent i7 = new Intent(getActivity(),IronGolem.class);
                startActivity(i7);
                break;
            case ACTIVITY_8:
                Intent i8 = new Intent(getActivity(),MagmaCube.class);
                startActivity(i8);
                break;
            case ACTIVITY_9:
                Intent i9 = new Intent(getActivity(),SilverFish.class);
                startActivity(i9);
                break;
            case ACTIVITY_10:
                Intent i10 = new Intent(getActivity(),Skeleton.class);
                startActivity(i10);
                break;
            case ACTIVITY_11:
                Intent i11 = new Intent(getActivity(),Slime.class);
                startActivity(i11);
                break;
            case ACTIVITY_12:
                Intent i12 = new Intent(getActivity(),SnowGolem.class);
                startActivity(i12);
                break;
            case ACTIVITY_13:
                Intent i13 = new Intent(getActivity(),Spider.class);
                startActivity(i13);
                break;
            case ACTIVITY_14:
                Intent i14 = new Intent(getActivity(),SpiderJockey.class);
                startActivity(i14);
                break;
            case ACTIVITY_15:
                Intent i15 = new Intent(getActivity(),Villager.class);
                startActivity(i15);
                break;
            case ACTIVITY_16:
                Intent i16 = new Intent(getActivity(),Witch.class);
                startActivity(i16);
                break;
            case ACTIVITY_17:
                Intent i17 = new Intent(getActivity(),Wither.class);
                startActivity(i17);
                break;
            case ACTIVITY_18:
                Intent i18 = new Intent(getActivity(),WitherSkeleton.class);
                startActivity(i18);
                break;
            case ACTIVITY_19:
                Intent i19 = new Intent(getActivity(),Zombie.class);
                startActivity(i19);
                break;
            case ACTIVITY_20:
                Intent i20 = new Intent(getActivity(),ZombiePigman.class);
                startActivity(i20);
                break;
            }
      }

目前,没有使用 commandsImages,因为我只是不知道将图像添加到列表视图的位置。任何帮助是极大的赞赏。谢谢!

4

0 回答 0