我正在尝试设置一个以编程方式创建的按钮,以便在单击时打开一个新活动并使用putExtra但是Activity在打开后甚至不会保持打开状态,它会保持1秒钟然后崩溃。
按钮代码:
blogs[i].setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.e("button", "blog clicked");
Intent i = new Intent(getSherlockActivity(), Soundcloud.class);
startActivity(i);
}
});
新班级:
public class Soundcloud extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.e("activity", "in activity");
setContentView(R.layout.soundcloud);
}
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
manifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.********"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET" />
<permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.*****.***.MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.*****.***.Soundcloud"
android:label="Blog" >
</activity>
</application>
</manifest>
logcat的:
07-24 22:27:22.310: E/pass 2.2(24015): blogs - connection success
07-24 22:27:23.990: E/button(24015): blog clicked
07-24 22:27:24.280: E/activity(24015): in activity
07-24 22:27:25.080: W/dalvikvm(24015): threadid=1: thread exiting with uncaught exception (group=0x40f21438)
答案 0 :(得分:0)
这应该完成它
blogs[i].setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.e("button", "blog clicked");
Intent i = new Intent(getActivity(), Soundcloud.class);
getActivity().startActivity(i);
}
});