ListView onItemClick按位置

时间:2011-11-21 21:40:41

标签: android listview onitemclicklistener onitemclick

我正在尝试这样做,当您单击第2行或第4行时,它运行的方法与列表项的其余部分不同。其余的去网站,但我想要第4行打开电子邮件,第2行打开导航器。但是,当我点击第4行时,它打开浏览器(即通过意图)然后在我退出后打开电子邮件。为什么? - 也是,导航器力关闭,但我认为它导致模拟器没有安装导航器:/任何建议?谢谢!

getListView()。setOnItemClickListener(new OnItemClickListener(){final String [] links = getResources()。getStringArray(com.BandCustomListView.R.array.ItemLinks);                 @覆盖             public void onItemClick(AdapterView parent,View view,int position,                     长id){

            String positions = links[position];

            if (position == 4){

                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);


                emailIntent.setType("plain/text");
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"Mtarpey@worcester.edu"});
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
                ;


                startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            }
             if (position == 2){
                Intent i = new Intent(Intent.ACTION_VIEW, 
                        Uri.parse("google.navigation:q=127+Southbridge+Street+Auburn+Massachusetts")); 
                        startActivity(i); 
            }
            if (position != (2 | 4)) {

            Intent SendToWebPageView = new Intent(getApplicationContext(), WebPageView.class);

            SendToWebPageView.setData(Uri.parse(positions));

            startActivity(SendToWebPageView);
            }
        }
        });

1 个答案:

答案 0 :(得分:0)

我想你可能想要改变这个LOC

if(position!=(2 | 4))

if(position!= 2&& position!= 4)

从4!= 2开始,在您执行检查以执行电子邮件意图后,它将通过该检查并启动网页视图。