1

this is the code in my custom adapter (THE CODE IN BROWN COLOR) when initially list is build proper margin is applied to valid items when i scroll down and again scroll up all the rows in list shifts the margin left by 20 what i'm doing wrong please reply soon

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        // getting data
        final ViewMovieDetailsModel_ViewComments movies = getItem(position);

        if (convertView == null) 
        {
            convertView = View.inflate(context, R.layout.comment_row, null);                
            holder = new ViewHolder();

            //getting handles

            holder.comments_linearLayout = (LinearLayout) convertView.findViewById(R.id.comments_linearLayout);
            holder.commenter_textView = (TextView) convertView.findViewById(R.id.comment_row_commenter);
            holder.commented_on_textView = (TextView) convertView.findViewById(R.id.comment_row_comment_time);
            holder.comment_text_textView = (TextView) convertView.findViewById(R.id.comment_row_comment_text);
            holder.reply_button = (Button) convertView.findViewById(R.id.comment_row_reply_button);

            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }

        if (movies != null) 
        {
            if (((movies.getParent_comment_id()).toString().equals("null")) && session.isLoggedIn()==true) {
                holder.reply_button.setVisibility(View.VISIBLE);
            }else{
                holder.reply_button.setVisibility(View.INVISIBLE);
            }


`if (!((movies.getParent_comment_id()).toString().equals("null"))) 
{

LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                    params.setMargins(20, 0, 0, 0);
                    holder.comments_linearLayout.setLayoutParams(params);
}`


            holder.commenter_textView.setText(movies.getUsername_commentor());

            holder.commenter_textView.setTag(movies.getUser_id_commentor());

        return convertView;
    }
Nitin Misra
  • 4,214
  • 3
  • 30
  • 52

2 Answers2

0

because you are setting margins (the brown font) in 'if' statement:

if (movies != null)

just take it out of this if block (for example put it just before the return point)

Right now this code is probably not executed at the first view load, since the movie is null. When the getView is called second time, the movie is not null, and the marigin is set according to your 'brown' code.

if this is not the solution - maybe the inside if statement condition is not true (the one that is in first 'brown' row). so.. your own logic prevents the marigins to be set as you want :)

Please let me know if it helps.

Jacek Milewski
  • 3,104
  • 1
  • 15
  • 17
  • doesn't help i assure u that IF condition i mentioned here is correct when first called the rows are set according to above given condition but when i scroll down and scroll up all the rows accqure same style please help i'm stuck at this for so long – Nitin Misra Jun 29 '13 at 17:06
  • I strongly recommend taing the Layout params settings out of very if, and place it right before return point. Just to try - it costs nothing. views in ListView are reused. So they are not being built from scratch every time. This is probably the reason why you have coditions like movie != null. – Jacek Milewski Jun 30 '13 at 13:24
  • or event simplier evidence: in 'brown' block of code place some breakpoint or log statement and check if it gets executed each time you expect it to – Jacek Milewski Jun 30 '13 at 13:25
  • I am not sure if I see corectly - does your return statement is in if(movies != null) block? – Jacek Milewski Jun 30 '13 at 13:28
  • thanx for help and for ur time too. I used (@Android Noob way) I am using Transparent image `VIEW.Gone` by default and when condition meet `VIEW.Visible`. Got it working (but don't know why Layout params not working) If u have some time can u please look at this http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser/17390977#17390977 – Nitin Misra Jun 30 '13 at 13:49
0

One way you could go about solving this problem is instead of using LayoutParams.setMargins(20, 0, 0, 0), you could create an empty TextView whose width is 20 dp by default and whose position will be to the left of your rows contents. It will be View.GONE by default, but when if (!((movies.getParent_comment_id()).toString().equals("null"))) happens, you can set that to View.VISIBLE

Android Noob
  • 3,040
  • 4
  • 29
  • 55