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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:12:29+00:00 2026-06-05T01:12:29+00:00

I’m testing code copied from a Java Android examples site. I’m trying to modify

  • 0

I’m testing code copied from a Java Android examples site. I’m trying to modify it to start a new activity when a user clicks into a row of the current activity. So I’m using the Intent method but I’m not able to figure out how to reference the current View instance argument to the Intent method.

I’ve tried dozens of combinations, and spent 2 days researching. This must seem basic to many of you I know, but my apologies, this is week #2 for me learning Java, Eclipse and the Android SDK (target= API 8)

    public class CustomListViewDemo extends ListActivity {
private EfficientAdapter adap;
private static String[] data = new String[] { "0", "1" };
private static String[] TitleString = new String[] { "Title1", "Title2" };
private static String[] DetailString = new String[] { "Detail1", "Detail2" };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    adap = new EfficientAdapter(this);
    setListAdapter(adap);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    Toast.makeText(this, "Click-" + String.valueOf(position),
            Toast.LENGTH_SHORT).show();
}

public static class EfficientAdapter extends BaseAdapter implements
        Filterable {
    private LayoutInflater mInflater;
    private Bitmap mIcon1;
    private Context context;

    public EfficientAdapter(Context context) {
        // Cache the LayoutInflate to avoid asking for a new one each time.
        mInflater = LayoutInflater.from(context);
        this.context = context;
    }

    /**
     * Make a view to hold each row.
     * 
     */
    public View getView(final int position, View convertView,
            ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.adaptor_content, null);

            holder = new ViewHolder();
            holder.textLine = (TextView) convertView
                    .findViewById(R.id.textLine);
            holder.buttonLine = (Button) convertView
                    .findViewById(R.id.buttonLine);
            holder.DbuttonLine = (Button) convertView
                    .findViewById(R.id.DbuttonLine);
            holder.textLine2 = (TextView) convertView
                    .findViewById(R.id.textLine2);

            convertView.setOnClickListener(new OnClickListener() {
                private int pos = position;

                @Override
                public void onClick(View v) {
                    // Toast.makeText(context, "Click-" +
                    // String.valueOf(pos),
                    // Toast.LENGTH_SHORT).show();

        // ******************** ERROR IS LINE BELOW *********
                    // "No enclosing instance of the type CustomListViewDemo is accessible in scope"
                    Intent i = new Intent(CustomListViewDemo.this, IntentA.class);
                    startActivity(i);

                }
            });


            holder.buttonLine.setOnClickListener(new OnClickListener() {
                private int pos = position;

                @Override
                public void onClick(View v) {
                    Toast.makeText(context,
                            "Delete-" + String.valueOf(pos),
                            Toast.LENGTH_SHORT).show();

                }
            });

            holder.DbuttonLine.setOnClickListener(new OnClickListener() {
                private int pos = position;

                @Override
                public void onClick(View v) {
                    Toast.makeText(context,
                            "Details-" + String.valueOf(pos),
                            Toast.LENGTH_SHORT).show();

                }
            });

            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textLine.setText(TitleString[position]
                + String.valueOf(position));
        holder.textLine2.setText(DetailString[position]
                + String.valueOf(position));

        return convertView;
    }

    static class ViewHolder {
        TextView textLine;
        TextView textLine2;
        Button buttonLine;
        Button DbuttonLine;

    }

    @Override
    public Filter getFilter() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return data[position];
    }

}

}

I have seen many examples about how to refer to outer members of nested classes but not found a good example on find the view instance of an outer class for use as a method argument. Can anyone point me in the right direction?

  • 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-05T01:12:32+00:00Added an answer on June 5, 2026 at 1:12 am

    If you look at the docs, the constructor you’re invoking (new Intent(CustomListViewDemo.this, IntentA.class)), is this one:

    public Intent (Context packageContext, Class<?> cls)
    

    Since you’re already storing a Context, you can fix your problem by using new Intent(this.context, IntentA.class) instead.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
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
Specifically, suppose I start with the string string =hello \'i am \' me And
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.