猿问

在数组项上设置意图 onclick

家伙,我真的想打开一个Activity与Intent从Searchview。我不知道该怎么做,这是我的代码


String dataArr[] = {

    "Kiambu county","Kisumu county","Kitui county",

    "Laikipia county","Lamu county","Makongeni county",

    "Meru county","Mombasa county","Muranga county",

    "Nairobi county","Nakuru county","Narok county",

    "kajiado county","kiambu county","Uansingishu county"

};

ArrayAdapter<String> newsAdapter = 

    new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, dataArr);

mSearchAutoComplete.setAdapter(newsAdapter);


// Listen to search view item on click event.

mSearchAutoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override

    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        if (i==0){

            Intent intent=new Intent(County.this,Kiambu.class);

        }

    }

});


// Below event is triggered when submit search query.

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

    @Override

    public boolean onQueryTextSubmit(String query) {

        AlertDialog alertDialog = new AlertDialog.Builder(County.this).create();

        alertDialog.setMessage("Search keyword is " + query);

        alertDialog.show();

        return false;

    }


    @Override

    public boolean onQueryTextChange(String newText) {

        return false;

    }

});

我真的很感激帮助,当我搜索一个词并点击它时,它会把我带到另一个班级


回首忆惘然
浏览 139回答 2
2回答

浮云间

开始活动(意图);在定义意图之后。只有当您的 i == 0(第一个元素)并且您不需要 i == 0 时,您才 onClick 工作。从控制元素的 ArrayAdapter 获取元素并传递到 Intent&nbsp;String art = arrayAdapter.get(i);if (art != null) {&nbsp; //here intent}还有 County.this,Kiambu.class... 是什么?

炎炎设计

然后,伙计们,但问题出在我的设备上,感谢您的答复
随时随地看视频慕课网APP

相关分类

Java
我要回答