标签: searchview

想要从 searchView 中删除搜索图标作为提示

    int magId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
    ImageView magImage = (ImageView) mSearchView.findViewById(magId);
    magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    magImage.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)

我正在使用上面的代码,但它并没有删除图标search。我已经设置了

 mSearchView.setIconified(false); 
Run Code Online (Sandbox Code Playgroud)

不明白为什么它仍然显示图标。

android searchview

0
推荐指数
1
解决办法
5267
查看次数

带有 Searchview 过滤器的 Recyclerview 不起作用

我正在使用本教程添加本地搜索,以查找RecyclerView来自 Web 服务的数据。问题是当我搜索某些内容时,仅显示前两项。每当我搜索某些东西时,这种情况就会发生。无论我输入什么,都只显示前两项。但是当我清除SearchView总列表时,再次显示哪个是正确的。但为什么实际搜索没有过滤出正确的项目呢?

public class ProductsByCategoryActivity extends AppCompatActivity implements SearchView.OnQueryTextListener {

    private RecyclerView recycler;
    private ProductsByCatAdapter adapter;
    private ArrayList<Model> arrayList = new ArrayList<Model>();
    private StaggeredGridLayoutManager gridmanager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_productbycategory);

        searchview = (SearchView) findViewById(R.id.searchview);

        cd = new ConnectionDetector(ProductsByCategoryActivity.this);
        recycler = (RecyclerView) findViewById(R.id.recycler);
        adapter = new ProductsByCatAdapter(ProductsByCategoryActivity.this, arrayList);
        recycler.setHasFixedSize(true);
        gridmanager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        gridmanager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
        recycler.setLayoutManager(gridmanager);
        recycler.setItemAnimator(null);
        recycler.setAdapter(adapter);

        searchview.setIconifiedByDefault(false);
        searchview.setOnQueryTextListener(this);
        searchview.setSubmitButtonEnabled(true);
        searchview.setQueryHint("Search Here");

        String URL = Utility.PRODBYEVERYTHING;
        prepareData(URL);
    }

    private void prepareData(final …
Run Code Online (Sandbox Code Playgroud)

android searchview android-recyclerview

0
推荐指数
1
解决办法
1416
查看次数

如何在 Room 中将 SearchView 与 LiveData 和 ViewModel 结合使用

我想使用 SearchView 搜索房间数据库中的某个元素,但我遇到了一个问题,因为我无法在 RecyclerViewAdapter 中使用 getFilter 因为我有 ViewModel 也许谁知道如何将所有这些元素组合到一个项目中。
\n我搜索一种使用 Transormations.switchMap 的方法。但我无法连接它们。

\n\n
\n

产品视图模型

\n
\n\n
class ProductViewModel(application: Application) : AndroidViewModel(application) {\n    private val repository: ProductRepository\n\n    val allProducts: LiveData<List<ProductEntity>>\n    private val searchStringLiveData = MutableLiveData<String>()\n\n    init {\n        val productDao = ProductsDB.getDatabase(application, viewModelScope).productDao()\n        repository = ProductRepository(productDao)\n        allProducts = repository.allProducts\n        searchStringLiveData.value = ""\n    }\n\n    fun insert(productEntity: ProductEntity) = viewModelScope.launch {\n        repository.insert(productEntity)\n    }\n\n\n    val products = Transformations.switchMap(searchStringLiveData) { string ->\n        repository.getAllListByName(string)\n\n    }\n\n    fun searchNameChanged(name: String) {\n        searchStringLiveData.value = name\n    }\n\n\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

产品道 …

android viewmodel kotlin searchview

0
推荐指数
1
解决办法
2441
查看次数

SearchView在ActionBar中的图标vom AppCompat总是有一个阴影

我在AppCompat Actionbar中包含了一个SearchView,但它的图标总是有阴影.

对于其他图标,我使用Android下载页面中没有阴影的图标,实际上我也尝试为SearchView直通分配图标android:icon="@drawable/ic_action_search"但不会更改图标.

搜索图标,带阴影

我的研究告诉我,实际上ab_ic_search.png来自android-support-v7-appcompat.jar正在被使用而我android:icon="@drawable/ic_action_search"被忽略了.

我尝试了各种各样的方法,比如尝试替换图像onPrepareOptionsMenu(通过尝试查找ImageView)或通过自定义子类SearchView但无效.

任何想法如何解决?基本上我只想让我的图标统一,我是否必须为所有其他图标添加阴影?可能我无论如何都无法为那些"三个点"添加阴影?

android android-appcompat android-actionbar searchview

-1
推荐指数
1
解决办法
1888
查看次数

getActivity().getComponentName()into Fragment Nullpointerexception

在多选项卡应用程序中,我在其中一个选项卡中添加了一个可扩展的列表视图和一个搜索视图(Tab2).我在getComponentName()上有一个错误,因为它不支持fragment.So我添加了getActivity().getComponentName().在此行上运行它时没有错误但是NullpointerException.应用程序崩溃.有任何想法吗?
以下是代码的重要部分:

public class Tab2 extends Fragment implements SearchView.OnQueryTextListener,SearchView.OnCloseListener{
private SearchView search;
private MylistAdapter listAdapter;
private ExpandableListView myList;
private ArrayList<Continent> continentList = new ArrayList<Continent>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.tab2, container, false);
    SearchManager searchManager = (SearchManager)  getActivity().getSystemService(Context.SEARCH_SERVICE);
    search = (SearchView) getActivity().findViewById(R.id.search);
    search.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    search.setIconifiedByDefault(false);
    search.setOnQueryTextListener(this);
    search.setOnCloseListener(this);

    displayList();
    expandAll();
    return rootView;
}



private void expandAll(){

    int count = listAdapter.getGroupCount();
    for (int i=0; i<count; i++)
    {
        myList.expandGroup(i);
    }
}

private void displayList() {

    // display …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception android-fragments searchview

-1
推荐指数
1
解决办法
2671
查看次数