Android - GridView项目单击打开所有布局

时间:2013-08-29 00:35:00

标签: android layout gridview android-intent click

我有这个问题。我有一个gridView,当我点击一个项目时,它应该打开一个布局但是我点击的每个按钮,打开每个布局,所以如果我按下后退按钮我需要按11次。我丢失的旧版本代码没有这个问题。求救!

public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list);
    GridView gridview = (GridView) findViewById(R.id.gv);
    gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
             switch(position)
                {
                case 0:               
                    Intent ammissione = (new Intent(List.this, Ammissione.class));             
                    startActivity(ammissione);

                case 1:
                    Intent organizzazione = (new Intent(List.this, Organizzazione.class));             
                    startActivity(organizzazione);

                case 2:
                    Intent notizie = (new Intent(List.this, Notizie.class));             
                    startActivity(notizie);

                case 3:
                    Intent percorsi = (new Intent(List.this, Percorsi.class));             
                    startActivity(percorsi);

                case 4:
                    Intent didattica = (new Intent(List.this, Didattica.class));             
                    startActivity(didattica);

                case 5:
                    Intent regolamenti = (new Intent(List.this, Regolamenti.class));             
                    startActivity(regolamenti);

                case 6:
                    Intent diploma = (new Intent(List.this, Diploma.class));             
                    startActivity(diploma);

                case 7:
                    Intent valutazione = (new Intent(List.this, Valutazione.class));             
                    startActivity(valutazione);

                case 8:
                    Intent perterritorio = (new Intent(List.this, PerTerritorio.class));             
                    startActivity(perterritorio);

                case 9:
                    Intent comunicazioni = (new Intent(List.this, Comunicazioni.class));             
                    startActivity(comunicazioni);

                case 10:
                    Intent europa = (new Intent(List.this, Europa.class));             
                    startActivity(europa);

                case 11: 
                    Intent ricerca = (new Intent(List.this, Ricerca.class));             
                    startActivity(ricerca);
                }


        }
    });
  }

1 个答案:

答案 0 :(得分:0)

您的break中缺少switch case声明。

在每break之后添加case,就像这样......

case 0:               
   Intent ammissione = (new Intent(List.this, Ammissione.class));             
   startActivity(ammissione);
   break;

请参阅The Switch Statement