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 9311445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:22:01+00:00 2026-06-19T01:22:01+00:00

I have a ArticlesAdapter which I am using to read remote JSON data. The

  • 0

I have a ArticlesAdapter which I am using to read remote JSON data. The adapter is working but I am struggling to get my ListView setonitemclicklister working.

What I am trying to accomplish is the ability to click on a ListItem and to get the Article data for the option clicked on.
I have functions like getName() in my Article class which I need to call in response to a ListItem click but I can’t seem to find a way to accomplish it.

I am trying to do this in my AsyncTask class.

Using the following code:

protected void onPostExecute(JSONArray result) {
            // TODO Auto-generated method stub

            Log.i("CHECK", "RESULTS: " + result);

            List<Article> articles = new ArrayList<Article>();

            String title = null;
            String nid = null;

            try{
                for(int i=0; i < data.length(); i++){
                    JSONObject dataObj = (JSONObject)data.get(i);
                    JSONObject record = dataObj.getJSONObject("node");
                    title = (record.getString("title"));
                    nid = (record.getString("nid"));

                    Log.i("FOUND", "title: " + title);
                    Log.i("FOUND", "nid: " + nid);

                    articles.add( new Article(title, "", Integer.parseInt(nid)) );
                }
            }catch(JSONException j){
                Log.e("CHECK", "Attempting to read data returned from JSONReader: " + j.toString());
            }

            ListView articlesList = (ListView)findViewById(R.id.articlesList);
            ArticleAdapter adapter = new ArticleAdapter(ArticlesActivity.this, R.layout.article_item, articles);
            articlesList.setAdapter(adapter);

            articlesList.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), "testing : ", Toast.LENGTH_LONG);
                    Log.i("CHECK", "AdapterView: " + parent);
                    Log.i("CHECK", "VIEW : " + view);
                    Log.i("CHECK", "POSITION : " + position);
                    Log.i("CHECK", "ID : " + id);
                }
            }); 

            if(dialog.isShowing())
                dialog.dismiss();
        }

My problem is I am not sure how to get the setOnItemClickListener working.
I am able to print the arguments via the Log function:

Log.i("CHECK", "AdapterView: " + parent);
Log.i("CHECK", "VIEW : " + view);
Log.i("CHECK", "POSITION : " + position);
Log.i("CHECK", "ID : " + id);

…but I get errors when I try casting any of the arguments into an Article object so I can call it’s getName() function etc.

  • 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-19T01:22:02+00:00Added an answer on June 19, 2026 at 1:22 am

    Your AsyncTask appears to be nested in your Activity, if it isn’t simply pass articles to your Activity, then use:

    articlesList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id){
            Article article = articles.get(position);
            // Do something with article
        }
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Tried using the following: Populate Listview from JSON To make a listview which uses
Have a text box which get data for price. If someone enter something like
Have got a method which returns IEnumerable<User> which I have been using Linq /
have numerous tests working, but my actual test of some objects is failing and
Have started working my way through a book called WebGL: Up and Running, which
Have been trying to get integration testing working with my seam project and the
Have you ever tried working with a XAML file which contains thousand tons of
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them

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.