views:

295

answers:

1

When i populate an ArrayAdapter, at first the rows in the visible part of the screen will be blank except the first row, which will be an undesired result. Then when I scroll it down and then come back all the screen will be set correctly...please some one tell me why this behavior happens ?

Code :

        homeListView = (ListView) findViewById(R.id.home_list);
        homeArrayAdapter = new HomeListArrayAdapter(this, R.id.home_list,
                homeList);
        homeListView.setAdapter(homeArrayAdapter);

Next Part as Class extending ArrayAdapter, an Inner Class to Activity:

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = inflater.inflate(R.layout.home, null);
        }

        Home item = (homeList).get(position);
        if (item != null) {
            if (item.type_text == Home.SIMPLE_SHOUT) {
                TextView tv1 = (TextView) findViewById(R.id.hTextView01);
                if (tv1 != null) {
                    tv1
                            .setText(String.format("   %s\t:",
                                    item.friend_name));
                    final String item_friend_id_01 = String
                            .valueOf(item.users_id);
                    tv1.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Toast toast = Toast.makeText(Tranz.this,
                                    item_friend_id_01, Toast.LENGTH_LONG);
                            toast.show();
                        }
                    });
                }
                TextView tv2 = (TextView) findViewById(R.id.hTextView02);
                if (tv2 != null) {
                    tv2.setText(String.format("\t%s", item.message));
                    tv2.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                        }
                    });

                }
                TextView tv3 = (TextView) findViewById(R.id.hTextView03);
                if (tv3 != null) {
                    tv3.setVisibility(0);
                    tv3.setText(null);
                    tv3.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                        }
                    });

                }
                ImageView imageView = (ImageView) findViewById(R.id.file_image);
                if (imageView != null) {
                    imageView.setBackgroundDrawable(null);
                }
            } else if (item.type_text == Home.FILE_SHOUT) {
                TextView tv1 = (TextView) findViewById(R.id.hTextView01);

The code is getting truncated, so the whole code is not appearing here. I'm sorry about that. Here what i have tried is to put the values in the object of class Home into two textViews and an ImageView, which may vary upon the value returned by variable item.type_text

Also if somebody can tell me another best practice to do this, please help.

+1  A: 

I'm not sure if this is the problem, but perhaps this will help.

I see you're passing null to LayoutInflater.inflate as the second parameter. Perhaps if you pass parent (which is the ViewGroup passed in as the third argument to getView(), probably your ListView) you will get better results.

synic
Thank you synic, but that didnt work...there was some error in my Inflater lines of code...but solved it by changing the Inflation codes to the codes given below...LayoutInflater inflater = context.getLayoutInflater();View view = inflater.inflate(R.layout.home_list, null);I don't know what is that happened, but that worked.Thanks again for your help.
Sumit M Asok