我用下面的代碼在主activity打開我自定義的類Speak2
Intent i = new Intent("R.voice.Speak2");
startActivity(i);
在voice.xml布局中設置的按鈕,當我點擊按鈕會調用activity Speak2。
沒有實現這個功能。
還有相關的代碼:
public class recon extends Activity implements OnClickListener{
ListView lv;
static final int check = 2000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.voice);
lv = (ListView)findViewById(R.id.lvVoiceReturn);
Button b = (Button)findViewById(R.id.bVoice);
b.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(recon.this , Speak2.class);
startActivity(i);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
}
}
請大家幫忙找找問題所在。
試下這個方法:
Intent i = new Intent(MainActivity.this , Speak2.class);
//MainActivity is your main activity
startActivity(i);
確保Activity Speak2
要在AndroidMenifest.xml
裡面定義,否則會獲得異常。
還有 AndroidMenifest.xml
中的<application> tag
應該是下面這樣的:
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" >
<activity android:label="@string/app_name" android:name="recon" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<Activity android:name="Speak2"/>
</application>