2017-07-16 107 views
-1

你好,我有一个问题,当我搜索的页面明天的过程是成功的,但是当我今天搜索页面上,有一个问题,我用片段搜索框不响应

问题就在这里: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; 
} 

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

请帮帮我,两个星​​期前,我一直在寻找一个问题

回答

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"); 
} 
+0

不工作:( –

+0

今天或10天搜索页面时,退出程序 –

+0

它显然会因为你在第一个片段而崩溃,并且你正在更改在onresume()方法中休息的搜索按钮单击最后一个片段的视图 –