android中的searchview在textview中搜索

时间:2014-07-15 10:32:16

标签: android searchview

是否可以实施searchview小部件以从textview进行搜索。我的textview看起来像这样

TextView TextView TextView

我使用layout inflater对这3个textviews进行了充气,​​以显示片段中的多个值。

片段类

public class MainFragment extends Fragment {
public View onCreateView (LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    // set the layout and inflater

    //perform some operations for button click
    return view;
}

活动类

public class MainActivity extends FragmentActivity{

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
            .add(R.id.container, new MainFragment()).commit();
    }
}

public boolean onOptionsItemSelected(MenuItem item) {
    //do some operations with overflow menu
}

public  ArrayList<Asset> getData() {
    //perform operations so that data can be sorted to an array and then passed to textviews
}

我对于在哪里包含searchview小部件以及如何使textview可搜索感到困惑。

1 个答案:

答案 0 :(得分:0)

您可以在on-create方法中包含搜索视图小部件,您可以按照这些链接获取代码:) 请访问:How to set edittext to show search button or enter button on keyboard? 并且还要看到这个:Android: Edittext acting as search engine 我希望这能帮助你找到答案,谢谢... :)