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

  • Home
  • SEARCH
  • 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 7823781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:22:29+00:00 2026-06-02T08:22:29+00:00

I’m currently building an app that has a request being sent into the web,

  • 0

I’m currently building an app that has a request being sent into the web, the result then gets parsed and put into an ArrayList of objects.

this list then, populates a ListView.
I want to create an onClickListener that will allow me to know which object was clicked, but I can’t find the correct way to implement this.

either assign the onClick to the ListView in the original activity, or, assign the listener within the getView function in the custom adapter.

it seems to me like assigning the listeners in the getView has too much overhead.

how does it work? what is better?

code for main activity:

public class NoPicList extends Activity {
    ListView list;
    NoPicAdapter adapter;
    ProgressDialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.no_pic_list);
        list = (ListView) findViewById(R.id.noPicListView);

        Bundle b = getIntent().getExtras();
        String request = b.getString("REQUEST");
        mDialog = new ProgressDialog(this);
        mDialog.setCancelable(false);
        mDialog.setMessage("Lodaing Data");
        mDialog.show();

        new GetNewsAndCalendar().execute(request);
    }

    @Override
    protected void onPause() {
        mDialog.dismiss();
        super.onPause();
    }

    class GetNewsAndCalendar extends
        AsyncTask<String, Void, ArrayList<Message>> {

        @Override
        protected ArrayList<Message> doInBackground(String... params) {
            String url = params[0];
            DOMFeedParser parser = new DOMFeedParser(url);
            return parser.parse();
        }

        @Override
        protected void onPostExecute(ArrayList<Message> result) {
            adapter = new NoPicAdapter(NoPicList.this, result);
            list.setAdapter(adapter);
            //FIRST OPTION TO INSERT onClickListener
            mDialog.dismiss();
        }
    }    //end of GetNewsAndCalendar
}

code for list adapter:

public class NoPicAdapter extends BaseAdapter {

    private ArrayList<Message> data;
    private Activity mActivity;
    private LayoutInflater inflater = null;

    public NoPicAdapter(Activity a, ArrayList<Message> result) {
        mActivity = a;
        data = result;
        inflater = (LayoutInflater) mActivity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (convertView == null)
            vi = LayoutInflater.from(mActivity).inflate(R.layout.no_pic_list_item,
                null);

        TextView title = (TextView) vi.findViewById(R.id.noPicTitle);
        TextView subtitle = (TextView) vi.findViewById(R.id.noPicSubtitle);

        title.setText(data.get(position).getTitle());
        subtitle.setText(data.get(position).getDate());
    // SECOND PLACE TO INSERT THE onClickListener
        return vi;
    }
}
  • 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-02T08:22:30+00:00Added an answer on June 2, 2026 at 8:22 am

    As per my concern, assign the onClick to the ListView in the original activity is good idea, rather then assigning it to in getView() of your custom adapter. Because in getView() of your adapter it always create a new View.onClick()’s object..

    list.setOnItemClickListener(new OnItemClickListener()
     {
      @Override
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
      {
       adapter.get(position);  
       // Get data from your adapter,   the above code of line give the custom adapter's object of   current position of selected list item     
      }   
     });  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.