带片段的搜索框没有响应

时间:2017-07-16 20:28:40

标签: android fragment

您好我明天搜索页面时遇到问题该过程成功但是当我今天搜索该页面时出现问题,我使用了Fragment

问题在于:https://www.youtube.com/watch?v=FiHGME6i97I&feature=youtu.be

代码:

public void btn_search(View view) {
    TextView txtexample = (TextView)findViewById(R.id.txtexample);
    txtexample.setText("hello");
}
片段天

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.user.weather.Fragment_days">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/txtexample"
        android:text="@string/hello_blank_fragment" />

</FrameLayout>
片段天

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_days, container, false);
    return v;
}

今天和明天的片段都是空的。

请帮助我,两周前我正在寻找一个问题

1 个答案:

答案 0 :(得分:0)

使用以下内容(请注意txtexample两行):

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_days, container, false);

    TextView txtexample = (TextView)v.findViewById(R.id.txtexample);                                       
    return v;
}

 public void btn_search(View view) {
     txtexample.setText("hello");
 }