0

Hey I am trying to display a web view if someone clicks on the 5th item in a list.

This is the code:

          lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position,
                long id) {

            if (position == 5) {

                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri uri = Uri.parse(href2_final
                                + "=service&doc_library=ABN01&doc_number="
                                + record_parsed_final
                                + "&line_number=0001&func_code=WEB-FULL&service_type=MEDIA");
                intent.setData(uri);
                startActivity(intent);
            }

        }

    });

What am I doing wrong? If I delete the IF statement then it will launch the web view when i press any item in the list.

Thanks!

Tbuermann
  • 93
  • 6

2 Answers2

2

As per your code, you must need to select 6th item in your ListView to call startActivity. For more info, read this

Community
  • 1
  • 1
waqaslam
  • 67,549
  • 16
  • 165
  • 178
0

I guess the fifth element is indexed in the position 4.

Chopin
  • 1,442
  • 17
  • 24