Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8631825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:16:14+00:00 2026-06-12T09:16:14+00:00

I am facing issues while trying to get the item selected in the listview.

  • 0

I am facing issues while trying to get the item selected in the listview. My activity has a tabbed layout with a ListView in one of the layouts.

Following is how I have populated the Listview :
This is how I declare the ListView in XML :

Category_list_display.xml

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/category_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:entries="@array/category_options">
</ListView>

Below is the array that I use for populating the ListView :

category_values.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="category_options">
        <item >Operating Systems</item>
        <item >Programming</item>
    </string-array>

</resources>    

Below is java code :

    package com.cheats;

    import android.os.Bundle;
    import android.support.v4.app.FragmentTransaction;
    import android.view.Window;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.TextView;
    import android.widget.Toast;
    import android.view.View;

    import com.actionbarsherlock.app.SherlockActivity;
    import com.actionbarsherlock.view.Menu;
    import com.actionbarsherlock.view.MenuItem;
    import com.actionbarsherlock.app.ActionBar;
    import com.actionbarsherlock.app.ActionBar.Tab;

    public class LandingPage extends SherlockActivity implements
            ActionBar.TabListener {

        private String[] tab_options = { "Categories", "Bookmarks", "Downloads" };
        private ListView category_tab_list;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setTheme(R.style.Theme_Sherlock_Light_DarkActionBar);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.splash_screen);

            getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            for (int i = 0; i <= 2; i++) {
                ActionBar.Tab tab = getSupportActionBar().newTab();
                tab.setText("Tab " + i);
                tab.setTabListener(this);
                tab.setText(tab_options[i]);
                getSupportActionBar().addTab(tab);
            }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {

            menu.add("New Update").setIcon(android.R.drawable.ic_menu_view)
                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

            menu.add("Search")
                    .setIcon(R.drawable.ic_search)
                    .setActionView(R.layout.collapsible_edittext)
                    .setShowAsAction(
                            MenuItem.SHOW_AS_ACTION_ALWAYS
                                    | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

            return true;
        }

        @Override
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub
            int nTabSelected = tab.getPosition();

            switch (nTabSelected) {

            case 0:
                setContentView(R.layout.category_list_display);
                category_tab_list = (ListView) findViewById(R.id.category_view);
                category_tab_list.setOnItemClickListener(new OnItemClickListener() {
                    public void onItemClick(AdapterView<?> myAdapter, View myView,
                            int myItemInt, long mylng) {
                        int selectedPosition = myAdapter.getSelectedItemPosition();
                        Toast.makeText(getApplicationContext(), myItemInt, Toast.LENGTH_SHORT).show();                  
                    }
                });
                break;
            case 1:
                setContentView(R.layout.splash_screen);
                break;
            case 2:
                setContentView(R.layout.splash_screen);
                break;
            }
        }

        @Override
        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            // TODO Auto-generated method stub

        }
    }

I get the following in the logcat when I try to run the above code :

    08-21 15:23:56.319: E/AndroidRuntime(1330): FATAL EXCEPTION: main
    08-21 15:23:56.319: E/AndroidRuntime(1330): android.content.res.Resources$NotFoundException: String resource ID #0x0
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.content.res.Resources.getText(Resources.java:201)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.widget.Toast.makeText(Toast.java:258)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at com.cheats.LandingPage$1.onItemClick(LandingPage.java:72)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.widget.ListView.performItemClick(ListView.java:3513)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.os.Handler.handleCallback(Handler.java:587)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.os.Handler.dispatchMessage(Handler.java:92)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.os.Looper.loop(Looper.java:123)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at java.lang.reflect.Method.invokeNative(Native Method)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at java.lang.reflect.Method.invoke(Method.java:507)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-21 15:23:56.319: E/AndroidRuntime(1330): at dalvik.system.NativeStart.main(Native Method)

I believe that the errors are coming because of the adapter not able to get the position. I do not have any explicit adapter as I am linking the array to ListView directly via XML. I want to keep the code this way. Is there a way I can get this resolved and the pass the selected value to a new activity with a new intent ?

I would be grateful for any help/suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:16:14+00:00Added an answer on June 12, 2026 at 9:16 am

    I was able to solve my problem by doing the following :

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        final String[] links = getResources().getStringArray(R.array.tut_titles);
        String link = links[position];
        Intent i = new Intent(Intent.ACTION_VIEW);  
        i.setData(Uri.parse(link));  
        startActivity(i);          
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to ASP.Net MVC 3, facing some issues while trying to implementing
I am trying to get data out of a list,but facing some issue while
Hi im trying to accomplish the following layout. I have two RelativeLayout, each one
I am facing some issues while serializing objects (I am using JBoss Drools, and
I am facing the following issue while uploading the video from my android application.
I am facing an issue regarding EF code first version while mapping one entity
i am facing issues while testing with the Test Accunt. i had entered correct
I am facing performance issues while reading/writing data from/to MS-Excel cells. I am using
I am facing a class resolution issue while trying to make my architecture flexible.
I'm facing the same issue, while trying for cross-domain request. Situation is strange, my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.