我已经为Android中的旋转器做了一个简单的演示,因为在第一个活动中进行了两个活动,在第二个活动中,第二个活动。以下代码但它不起作用:
Activity1.java
package com.example.sppiner;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
public class MainActivity extends Activity {
Spinner sp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp=(Spinner)findViewById(R.id.spinner1);
String[] s={"ahmedabad","baroda","chitor","daman","england","france","georgia"};
sp.setAdapter(new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,s));
sp.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String n = (String)arg0.getItemAtPosition(arg2);
Intent i =new Intent(MainActivity.this,Act2.class);
Bundle b =new Bundle();
i.putExtra("nat", n);
startActivity(i);
}
});
}
}
act2.java
package com.example.sppiner;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TextView;
public class Act2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_act2);
TextView tv =(TextView)findViewById(R.id.tv1);
Bundle b = getIntent().getExtras();
Intent i =getIntent();
String nat = b.getString("nat");
tv.setText(nat);
}
}
请帮助我...在此先感谢