简体   繁体   English

当您单击微调器中的项目并传递数据时,如何打开新活动,是否有可能我们无法通过微调器打开新活动?

[英]how to open new activity when you click an item in spinner and pass data, and is it possible we cant open new activity through spinner?

public class BekaaActivity extends Activity implements AdapterView.OnItemSelectedListener{
Spinner bekaa=null;
Intent intent;
String[] info;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bekaaarea);
    bekaa=(Spinner)findViewById(R.id.spinner1);
    bekaa.setOnItemSelectedListener(this);

}

public void onNothingSelected(AdapterViewparent){} 公共无效onNothingSelected(AdapterViewparent){}

public void onItemSelected(AdapterView<?>parent,View view,int pos,long id){




    if(((TextView)view).getText().equals("Sohmor")){

         String[] info = {"Adel","70858243","8-10-12","70$","sohmor"};





                Intent i = new Intent("net.learn2develop.AutocarActivity");
                Bundle extras = new Bundle();
                extras.putStringArray("strings",info);

                i.putExtras(extras);
                startActivityForResult(i, 1);



    }



//tv1.setText(((TextView)view).getText());

}

Whenever i click Sohmor item, the application crashes, i don't know why . 每当我单击Sohmor项目时,应用程序就会崩溃,我不知道为什么。 i followed the error and i find it when i want to start new Activity here's the log 04-05 22:55:02.157: D/dalvikvm(12477): GC_FOR_ALLOC freed 61K, 27% free 2752K/3728K, paused 0ms, total 0ms 04-05 22:55:02.157: I/dalvikvm-heap(12477): Grow heap (frag case) to 2.999MB for 294384-byte allocation 04-05 22:55:02.187: D/dalvikvm(12477): GC_FOR_ALLOC freed <1K, 25% free 3039K/4016K, paused 30ms, total 30ms 04-05 22:55:02.477: I/PGA(12477): Attempting to create new SOCKET connectionn pid = 12477, tid = 12477 04-05 22:55:02.487: I/PGA(12477): New SOCKET connection: com.example.liutransportations (pid 12477, tid 12477) 04-05 22:55:11.077: W/InputEventReceiver(12477): Attempted to finish an input event but the input event receiver has already been disposed. 我遵循了错误,当我想开始新活动时找到了它,这里是日志04-05 22:55:02.157:D / dalvikvm(12477):GC_FOR_ALLOC释放了61K,27%释放了2752K / 3728K,暂停了0ms,总计0ms 04-05 22:55:02.157:I / dalvikvm-heap(12477):将堆(片段大小写)增长到2.999MB以用于294384字节分配04-05 22:55:02.187:D / dalvikvm(12477):GC_FOR_ALLOC已释放<1K,25%空闲3039K / 4016K,暂停30ms,总计30ms 04-05 22:55:02.477:I / PGA(12477):尝试创建新的SOCKET连接n pid = 12477,tid = 12477 04-05 22:55 :02.487:I / PGA(12477):新的SOCKET连接:com.example.liutransportations(pid 12477,tid 12477)04-05 22:55:11.077:W / InputEventReceiver(12477):试图完成输入事件输入事件接收器已被处置。 04-05 22:55:11.227: W/Instrumentation(12477): Unresolved intent: cmp: null 04-05 22:55:11.227: W/Instrumentation(12477): Unresolved intent: data: 04-05 22:55:11.227: D/AndroidRuntime(12477): Shutting down VM 04-05 22:55:11.227: W/dalvikvm(12477): threadid=1: thread exiting with uncaught exception (group=0x95d28b20) 04-05 22:55:11.227: I/Process(12477): Sending signal. 04-05 22:55:11.227:W / Instrumentation(12477):未解决的意图:cmp:空04-05 22:55:11.227:W / Instrumentation(12477):未解决的意图:数据:04-05 22:55: 11.227:D / AndroidRuntime(12477):关闭VM 04-05 22:55:11.227:W / dalvikvm(12477):threadid = 1:线程退出且未捕获(group = 0x95d28b20)04-05 22:55:11.227 :I / Process(12477):正在发送信号。 PID: 12477 SIG: 9 PID:12477 SIG:9

What is this? 这是什么?

Intent i = new Intent("net.learn2develop.AutocarActivity");

if you have an activity with name "AutocarActivity" and you want to open it try this code 如果您有一个名为“ AutocarActivity”的活动,并且想要打开它,请尝试以下代码

Intent i = new Intent(this, AutocarActivity.class);
                Bundle extras = new Bundle();
                extras.putStringArray("strings",info);

                i.putExtras(extras);
                startActivityForResult(i, 1);

Not: You must to declare the activity in your manifest file So you must to replace 否:您必须在清单文件中声明活动,因此必须替换

Intent i = new Intent("net.learn2develop.AutocarActivity");

With : 与:

Intent i = new Intent(this, AutocarActivity.class);

For more info about intents Intent class 有关意图的更多信息意图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM