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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:21:25+00:00 2026-06-18T08:21:25+00:00

I have an activity that displays information about a player. This part works fine.

  • 0

I have an activity that displays information about a player. This part works fine. (I used an adapter). But where should I put the code that detects when a row is clicked?

PlayersActivity.java

package com.democratandchronicle.billstrainingcamp;

import android.os.Bundle;

public class PlayersActivity extends ListActivity 
{

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_players);
        PlayersAdapter adapter = new PlayersAdapter(this);
        getListView().setAdapter(adapter);
        PlayersFetchTask loadPlayersTask = new PlayersFetchTask(adapter);
        loadPlayersTask.execute(); 
    }
}

PlayersAdapter.java

package com.democratandchronicle.billstrainingcamp;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class PlayersAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater layoutInflater;
    private JSONArray entries = new JSONArray();
    private DrawableManager dm;
    public PlayersAdapter(Context context) {
        super();
        this.context = context;
        this.layoutInflater = (LayoutInflater) this.context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.dm = new DrawableManager();
    }

    @Override
    public int getCount() {
        return this.entries.length();
    }

    @Override
    public Object getItem(int position) {
        try {
            return this.entries.getJSONObject(position);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        RelativeLayout playerRowView;

        if (convertView == null)
        {
            playerRowView = (RelativeLayout) this.layoutInflater.inflate(R.layout.player_row, parent, false);
        }
        else
        {
            playerRowView = (RelativeLayout) convertView;
        }

        TextView playerNameText = (TextView) playerRowView.findViewById(R.id.playerName);
        TextView playerPositionText = (TextView) playerRowView.findViewById(R.id.playerPosition);
        ImageView playerImageView = (ImageView) playerRowView.findViewById(R.id.playerImage);

        try 
        {
            JSONObject dataRow = this.entries.getJSONObject(position);
            playerNameText.setText(dataRow.getString("firstName") + " "+ dataRow.getString("lastName"));
            playerPositionText.setText(dataRow.getString("position"));
            if (!dataRow.getString("photo").equals(""))
            {
                this.dm.fetchDrawableOnThread(dataRow.getString("photo"), playerImageView);
            }

        } 
        catch (JSONException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return playerRowView;
    }

    public void upDateEntries(JSONArray entries)
    {
        this.entries = entries;
        this.notifyDataSetChanged();
    }

}
  • 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-18T08:21:26+00:00Added an answer on June 18, 2026 at 8:21 am

    Where should I put the code that detects when a row is clicked?

    To detect a click anywhere on the row, use an OnItemClickListener in your Activity.

    To detect clicks in different regions on each row, use OnClickListeners inside your Adapter’s getView().

    Also you can create a slightly faster Adapter if you use the ViewHolder method. The Google Talk TurboCharge Your UI discussions this and other good practices in detail.


    Addition

    How would I do this in my activity?

    ListActivities have an OnListItemClick built-in, the callback has a slightly different name: onListItemClick(). Use it like so:

    @Override
    protected void onListItemClick (ListView l, View v, int position, long id) {
        Toast.makeText(this, "Clicked row " + position, Toast.LENGTH_SHORT).show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Activity that retrieves information from a remote server and displays it
I have an app that displays a splash screen. The splash screen activity creates
I have an Activity that should only get created once. That is, onCreate can
I have an activity that displays a list of restaurant dishes. Each view of
I have an activity that displays a list of main menu items. Each list
I currently have a ListView with a custom adapter that gets information describing the
I have an AsyncTask that retrieves information from the internet. But when signal or
I have a C# application that allows one user to enter information about customers
In our Android app, I have an activity that has a gridview that displays
I have a simple app that reads internet resource and displays the information in

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.