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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:52:35+00:00 2026-05-30T02:52:35+00:00

I have a strange error in my code and i can’t see the problem.

  • 0

I have a strange error in my code and i can’t see the problem. I have a main class where I have an other class inside. I have an arraylist declared in the main class and if I acces to it in somepart of the class i can have all the information but when i acces to it in the inner class it can’t see the data. Why?

The inner class is an BaseAdapter for making a viewlist. I called it from oncreate bundle as:

public class Main extends ListActivity implements OnClickListener {
//new adapter
private EfficientAdapter adap;
//The variable which makes the error
public static ArrayList<String> data2 = new ArrayList<String>();    
protected static Context mContext=null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nuevoingr);

    data2.clear();
    data2.add("just adding 1");
    adap = new EfficientAdapter(this);
    setListAdapter(adap);

and the inner class is (the problem is at the end of it):

public static class EfficientAdapter extends BaseAdapter implements Filterable {
    private LayoutInflater mInflater;
    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.
     *
     * @see android.widget.ListAdapter#getView(int, android.view.View,
    *      android.view.ViewGroup)
    */
    public View getView(final int position, View convertView, ViewGroup parent) {
        // A ViewHolder keeps references to children views to avoid
        // unneccessary calls
        // to findViewById() on each row.
        ViewHolder holder;

        // When convertView is not null, we can reuse it directly, there is
        // no need
        // to reinflate it. We only inflate a new View when the convertView
        // supplied
        // by ListView is null.
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.pruebas, null);

            // Creates a ViewHolder and store references to the two children
            // views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.textLine = (TextView) convertView.findViewById(R.id.pr2);
            holder.buttonLine = (ImageButton) convertView.findViewById(R.id.pr1);


            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();   
                }
            });

            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();     
                }
            });
            convertView.setTag(holder);
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        }

        // Bind the data efficiently with the holder.
        holder.textLine.setText(String.valueOf(position));

        return convertView;
    }

    static class ViewHolder {
        TextView textLine;
        ImageButton buttonLine;
    }

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

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


//Here it comes the problem. Before editing my program this code was provide to include     only a few values from 
a String array declared at the same moment of data2 called data. What I do now is to     declare an arraylist so
 I can include more values and then I refresh the adaptor and here I pass the arraylist     to an array to be equal as
 it was before.
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        String [] change = (String[]) data2.toArray(new String[data2.size()]);  
        return change.length;
        //return data.length;
    }
//Same problem   
    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub

        String [] change = (String[]) data2.toArray(new String[data2.size()]);
        return change[position];
        //return data[position];
    }

}

What is strange is that this baseAdapter is for a listview and when it updates it’s data there’s as rows as arraylist.length but its data it’s not include it and all rows are detected as the same when clicking it.

  • 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-30T02:52:36+00:00Added an answer on May 30, 2026 at 2:52 am

    Problem solved.
    I changed the code to this one: techdroid.kbeanie.com/2009/07/custom-listview-for-android.html

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

Sidebar

Related Questions

I have a very strange problem and the following code wont compile: #ifndef MYWINDOW_HPP_INCLUDED
I have a strange problem with the following code: MembersDetailViewController *m = [[MembersDetailViewController alloc]
I have strange problem. I have 3 forms. form1, form2, form3. form1 is starting/main
I have run into a pretty strange error that I can't get my head
Everybody out there, I'm writing a c code which have a strange problem when
I have a strange problem in C about including header files. main.c #include <stdio.h>
I have a very strange error in my Qt project. Here is the code,
I have some strange problem. I think I followed documentation correctly but my code
I have a very strange error using NSMutableArray in cocos2d/xcode In my code, I
I have a strange error where my jquery ajax request doesn't submit all the

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.