【发布时间】:2014-11-29 22:52:55
【问题描述】:
我是 Android 编程新手。我有一个问题,我如何才能从片段到活动。
我试图对其进行编码,但我失败了:(('l_places' 是 Fragment Places 的布局,'p_tr_fr' 是可点击的 TableRow)
这是我的片段代码:
package com.fragment.toactivity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Places extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.l_places, container, false);//l_places is the layout
return rootView;
}
public void goToAttract(View v)
{
if (v.getId()== R.id.p_tr_fr) {
Intent intent = new Intent(getActivity(), Listact.class);
startActivity(intent);
}
}
public View onCreateView(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
};
}
这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffd4d4d4">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/scrollView2" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#ffffffff">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_gravity="bottom"
style="@android:style/Widget.AutoCompleteTextView"
android:layout_margin="0dp"
android:id="@+id/p_tr_fr"
android:onClick="onClick">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/imageView2"
android:src="@drawable/m_pf"
android:scaleType="fitCenter"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/s_shop"
android:id="@+id/textView3"
android:layout_column="1"
android:layout_gravity="center_vertical"
android:textStyle="bold"
android:textSize="18dp"
android:textColor="#ff000000"
android:layout_marginLeft="6dp" />
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
当我单击 TableRow 时,应用程序停止。请帮忙! (对不起我的英语)
【问题讨论】:
-
我忘记写了,Listact的布局是空的,所以我认为错误不会在那里
标签: java android android-intent android-activity android-fragments