alllllllll 2013-04-27 07:12 采纳率: 0%
浏览 2347
已采纳

从spinner中开始新的activity

需要实现的功能是spinner中一个选项可以开始一个新的activity。但是应用每次执行到这都会崩溃。我用了intent和onItemSelected 。不知道哪里出现的问题,请高手指教,谢谢。

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TextView;
public class Abs extends Activity {
private Spinner StretchType;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    setContentView(R.layout.abs);
    addListenerOnSpinnerItemSelection();
    tv = (TextView) findViewById(R.id.tvTypeofStretch);
}
public void addListenerOnSpinnerItemSelection() {
    StretchType = (Spinner) findViewById(R.id.sSType);
    StretchType
            .setOnItemSelectedListener(new CustomOnItemSelectedListener());
}

public class CustomOnItemSelectedListener extends Activity implements
        OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos,
            long id) {
 // **************************** below here is where I start the new activity
        switch (pos) {
        case (1):
            Intent i = new Intent(this, Practice.class);
            startActivity(i);
            break;
        }
        // **************************** above here is where I start the new activity
    }
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
    }
}
}
  • 写回答

2条回答

  • jnhoodlum 2013-04-27 08:23
    关注

    public class CustomOnItemSelectedListener extends Activity implements
            OnItemSelectedListener {
    
        public void onItemSelected(AdapterView<?> parent, View view, int pos,
                long id) {
     // **************************** below here is where I start the new activity
            switch (pos) {
            case (1):
                Intent i = new Intent(this, Practice.class);
                startActivity(i);
                break;
            }
            // **************************** above here is where I start the new activity
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    }
    

    改成

    **public class CustomOnItemSelectedListener implements
            OnItemSelectedListener**  {
    
        public void onItemSelected(AdapterView<?> parent, View view, int pos,
                long id) {
     // **************************** below here is where I start the new activity
            switch (pos) {
            case (1):
                Intent i = new Intent(this, Practice.class);
                 **Abs.this.startActivity(i);** 
                break;
            }
            // **************************** above here is where I start the new activity
        }
        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    }
    

    试试

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮