Adam
Adam

Reputation: 13

Index of the item that is clicked in ListView

Android: Hello, i am trying to get index of the item that is clicked but i don't know how i can do it. I want if i click on any item in listview it will open SmsManager with number of this item(Phone Number). Can somebody tell me how i can do it?

There is source code:

 list1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int position,
                    long id) {
                SmsManager m = SmsManager.getDefault();
                Uri uriSMSURIs = Uri.parse("content://sms/inbox");
                Cursor cc = getContentResolver().query(uriSMSURIs, null, null, null, null);
                String phoneNumber  = cc.getString(cc.getColumnIndex("address"));
                m.sendTextMessage(phoneNumber , null, phoneNumber , null, null);


            }

        });

Upvotes: 1

Views: 1018

Answers (2)

Jorgesys
Jorgesys

Reputation: 126563

Implement

onListItemClick

    @Override
    protected void onListItemClick(ListView l, View v, final int position, long id) {
        super.onListItemClick(l, v, position, id);  

Log.i("the Item clicked is :: ",  position);

    }

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007614

The "index of the item witch [sic] is clicked" is the position parameter supplied to onItemClick().

Upvotes: 2

Related Questions