已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题吗?**通过editing this post添加详细信息并阐明问题。
25天前关闭。
Improve this question
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
myView = inflater.inflate(R.layout.first_layout, container, false);
tv.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
tv = (TextView) myView.findViewById(R.id.textView);
Intent i = new Intent();
i.setClass(getActivity(), Second_Fragment.class);
startActivity(i);
}
});
return myView;
}
XML程式码:
<ImageView
android:src="@drawable/processor"
android:layout_width="150dp"
android:layout_height="80dp"
android:id="@+id/imageView"
android:layout_weight="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Processor"
android:textSize="25dp"
android:id="@+id/textView2"
android:layout_weight="2"
android:clickable="true"/>
</TableRow>
错误代码:
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:57)
at android.os.Binder.execTransact(Binder.java:446)
07-13 04:47:09.009 1082-1092/android.process.acore E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:64)
at android.os.Binder.execTransact(Binder.java:446)
07-13 04:47:09.236 1082-1092/android.process.acore E/StrictMode﹕ A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:184)
at android.os.ParcelFileDescriptor.<init>(ParcelFileDescriptor.java:180)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:916)
at android.os.ParcelFileDescriptor$1.createFromParcel(ParcelFileDescriptor.java:906)
at android.app.IBackupAgent$Stub.onTransact(IBackupAgent.java:71)
at android.os.Binder.execTransact(Binder.java:446)
3条答案
按热度按时间ppcbkaq51#
第一:你没有开始一个片段调用:
该方法的名称很清楚:启动活动(i);所以,你应该学习如何开始一个片段,而不是开始一个活动!
第二:把:
在setOnClickListener(...)之前;
x9ybnkn62#
你不能通过
startActivity()
附加片段,假设你的Second_Fragment.class
是一个片段。从文档中,添加要进行分段的视图:
然后通过
FragmentManager
将其附加到onClick中的此视图:46qrfjad3#
您可以在Activity和fragment中使用interface,每当您单击fragment中的textview时,就会通过interface向Activity发送数据,并从Activity更新fragment。为此,您必须使用onAttach()方法