这是我的滑动片段的java代码,我在该片段中做了一个布局, 我想让“正在进行的”RelativeLayout可点击以导航到其他活动。 请帮我解决这个问题。
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import info.androidhive.CrescentBuilders.R;
public class Ongoing extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View android = inflater.inflate(R.layout.ongoing_frag, container, false);
//((TextView)android.findViewById(R.id.textView)).setText("Ongoing Projects");
RelativeLayout ongoing=(RelativeLayout)android.findViewById(R.id.layoutongoing);
return android;
}
}
答案 0 :(得分:1)
如果布局在片段
中,您应该在onViewCreated而不是onCreateView中找到Id@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View android = inflater.inflate(R.layout.ongoing_frag, container, false);
return android;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
RelativeLayout ongoing=(RelativeLayout)view.findViewById(R.id.layoutongoing);
}