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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:13:44+00:00 2026-05-16T08:13:44+00:00

I have got ListView with a custom Adapter. Every row contains clickable buttons and

  • 0

I have got ListView with a custom Adapter. Every row contains clickable buttons and texts.

At the moment onClickListeners are set in the body of getView(), this is quite insane idea because this method is called very frequently. Inside every onClick function, I need access to the private data to call new activity with the bundle.

How can I move the onClick definition outside getView() routine?

When onClick will be called I need info about the position of the list element (to access private data) and which View was clicked (to start the correct Activity).

public View getView(int position, View convertView, ViewGroup parent) {
    if(convertview == null) {
        convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.photo_tweet_row, null);
    }

    TextView userTweet = (TextView) v.findViewById(R.id.feed_user_tweet_body);
    RepliesButton repliesBtn = (RepliesButton) v.findViewById(R.id.feed_replies_button);

    Status twitterDataItem = getItem(position);

    if (twitterDataItem != null) {

        if (userTweet != null) {
            userTweet.setText(twitterDataItem.getText());
        }
        if (repliesBtn != null) {
            repliesBtn.setText(" replies");
        }
        
        userTweet.setOnClickListener(new View.OnClickListener() {           
            @Override
            public void onClick(View v) {                    
              Intent intent = new Intent(getContext(), ProfileActivity.class); 
              intent.putExtra(getContext().getString(R.string.serializable_user), twitterDataItem.getUser());
              getContext().startActivity(intent);
            }
        });
        
        repliesBtn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                if (!twitterDataItem.getComments().contentEquals("0")) {
                    Intent myIntent = new Intent(getContext(), RepliesToFeedActivity.class);
                    myIntent.putExtra("photoTweet", twitterDataItem);
                    getContext().startActivity(myIntent);
                }
            }
        });
    }
    return convertView;
}
  • 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-05-16T08:13:45+00:00Added an answer on May 16, 2026 at 8:13 am

    Your activitiy has to implement the OnClickListener, and move the implemented method up to the activity level.

    Based on the view parameter of the method you are able to detect from which UI object the event came from (button, textview).

    As for how to detect for which record/row in a listview. You have to set a custom tag on the buttons and textviews in the getView method, that you will read in the event via getTag this tag can be a custom object too if string is not enough. Probably/recommended way is to be the position in the adapter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible
We have got loads of options for php + MySQL + Apache combo... Which
I have got a python script which is creating an ODBC connection. The ODBC
I have got a C function in a static library, let's call it A,
I have got the following problem since the server has safe mode turned on,
I have got some code to load an assembly and get all types, which
I have got the following code from here to read an Excel file using
I have got a table in MS Access 2007 with 4 fields. Labour Cost
I have got this error when using Enterprise Library 3.1 May 2007 version. We
I have got two classes, one a subclass of the other (say Animal and

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.