【问题标题】:adding intents to item in searchable listView向可搜索列表视图中的项目添加意图
【发布时间】:2017-03-07 03:13:33
【问题描述】:

我是初学者。我正在开发一个包含更多活动的应用程序。我的 MainActivity 中有一个 listView ,工具栏中有 searchView 。现在我需要通过搜索 listView 并单击 listView 中的项目来打开其他活动。 帮帮我..

ArrayList<String> arrayCountry = new ArrayList<>();
        arrayCountry.addAll(Arrays.asList(getResources().getStringArray(R.array.array_country)));

        adapter = new ArrayAdapter<>(
                MainActivity.this,
                android.R.layout.simple_list_item_1,
                arrayCountry);
        lv.setAdapter(adapter);


        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String arrayCountry = lv.getAdapter().toString();

            }
        });

【问题讨论】:

    标签: android listview android-intent


    【解决方案1】:

    只需将意图放在您的 itemClickListener 中。

    onItemClick() {
        Intent intent = new Intent(MainActivity.this, <ACTIVITY_NAME>.class);
        startActivity(intent);
    }
    

    我不确定这是否正是您要查找的内容,因为您的描述有点模糊,但这将毫无问题地开始一项新活动。

    【讨论】:

    • 您发送的代码将启动 .class... 但是我想针对 listView 中的项目启动其他活动...抱歉我的模糊问题...可以你帮我修改我的问题?
    【解决方案2】:

    我想这就是你一直在寻找的,

    Object GetLabel = lv.getItemAtPosition(position);
                            if (GetLabel.toString().equals("label1")) {
                                Intent intent = new Intent(MainActivity.this, label1.class);
                                startActivity(intent);
                            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      相关资源
      最近更新 更多