ListView打开一个新活动

时间:2013-07-25 12:08:21

标签: java android android-listview

这是一个更加以设计为中心的问题。但我正在考虑开发一个应用程序,它将包含一个包含例如咖啡名称数组的ListView。

现在,当用户点击咖啡名称时,我想要了解咖啡风格的详细信息页面以及如何制作咖啡。基本上只是想象一个包含大量信息的新窗口。

我的主要问题是,你认为最好的方法是在ListView上点击一个新的活动吗?我是Android的新手,因此我不确定是否有更简单的方法来执行此操作。

感谢任何可以提供帮助的人!

3 个答案:

答案 0 :(得分:2)

你是对的,点击列表项创建一个新活动是正确的方法。

答案 1 :(得分:0)

如果您是新手,而您的客户也是新手,那就是这样:打开详细信息页面,新活动(detail.xml布局)并用选定的咖啡填充。

如果您的客户需要一个精美的应用程序并且在...之上,那么他会要求您提供ExpandableList,这也取决于应用程序。

答案 2 :(得分:0)

在我当前的应用程序中,我在片段中创建了listview。我会在片段中设置一个监听器,这会将我的所有数据传递给一个新的活动。

 listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //goes to new activity passing the item name
            Intent intent = new Intent(view.getContext(), MapsActivity.class);
            Bundle b = new Bundle();

            //get text for current item
            String textGet = mylist1.get(position);

            //put text into a bundle and add to intent
            intent.putExtra("text", textGet);

            //get position to carry integer
            intent.putExtra("position", position);

            intent.putExtras(b);

            //begin other activity
            startActivity(intent);
        }
    });