0

我正在开发 Android 应用程序。当我按下后退按钮时,它说应用程序已停止。

下面是我的代码:

     list.setOnItemClickListener( new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {

                switch(position){

                case 1 : Intent intent = new Intent(Product.this, Desktop.class);

                         intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                         startActivityForResult(intent, 1);

                         break;
                case 2 : Intent intent1 = new Intent(Product.this, Notebook.class);
                         intent1.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                         startActivityForResult(intent1, 2);

                         break;

               default : break;

                }
            }   
        });



@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.desktop);


        gridView = (GridView) findViewById(R.id.gridView1);

        gridView.setAdapter(new ImageAdapter(this, comps));

        gridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {
                Toast.makeText(
                   getApplicationContext(),
                   ((TextView) v.findViewById(R.id.grid_item_label))
                   .getText(), Toast.LENGTH_SHORT).show();

            }
        });

    }

}

我应该添加什么以便它将转到上一个活动?

4

1 回答 1

0

写下面的代码片段而不是您的代码,可能会解决您的问题。

case 1 : Intent intent = new Intent(Product.this, Desktop.class);
         startActivity(intent);

         break;

case 2 : Intent intent1 = new Intent(Product.this, Notebook.class);
         startActivity(intent1);

         break;
于 2012-11-21T08:53:19.560 回答