1

I got a problem when redraw layout again , firstly i get list of comments and it to layout with inflate , but when i need to add comment to list of comments i try to remove all views from parent layout and add it again , my problem be when i redraw the layout again it override on the old view

int counter_add_tolayout= 0;

private void InitializeLayoutComments(CommentModel commentModel) {
    // TODO Auto-generated method stub
    final View layout = LayoutInflater.from(this).inflate(
            R.layout.item_comment_list,
            layout_commentsList_container_PostActivity, false);
    layout.setTag("" + counter_add_tolayout);
    counter_add_tolayout++;
    ProgressBar progressprofilepic_commentitem = (ProgressBar) layout
            .findViewById(R.id.progressprofilepic_commentitem);
    ImageView imgview_profilepic_commentitem = (ImageView) layout
            .findViewById(R.id.imgview_profilepic_commentitem);
    TextView txtview_commentusername_commentitem = (TextView) layout
            .findViewById(R.id.txtview_commentusername_commentitem);
    TextView txtview_commentTime_commentitem = (TextView) layout
            .findViewById(R.id.txtview_commentTime_commentitem);
    TextView txtview_commentbody_commentitem = (TextView) layout
            .findViewById(R.id.txtview_commentbody_commentitem);
    String uri = "http://newcairo.net/photos/small-"
            + commentModel.getCuserid() + ".jpg";
    Load_Picture(imgview_profilepic_commentitem, uri,
            progressprofilepic_commentitem);
    txtview_commentusername_commentitem
            .setText(commentModel.getCusername());
    txtview_commentbody_commentitem.setText(commentModel.getComment());

    if (commentModel.getComment_Status().equals(CommonUtilities.UPLOADING)) {
        InitAnimation(.5f);
        layout.startAnimation(alfaAnimation);
        txtview_commentTime_commentitem
                .setText(CommonUtilities.UPLOADING);
        int position = Integer
                .parseInt(layout.getTag().toString());
        new AddCommentWebTask(position, commentModel,
                commentModel.getUploading_status()).execute();
    } else {
        InitAnimation(1);
        layout.startAnimation(alfaAnimation);
        String commentTime = CommonUtilities
                .getRelativeTimeSpanString(commentModel.getCommentdate());
        txtview_commentTime_commentitem.setText(commentTime);
    }


    imgview_profilepic_commentitem
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    int position = Integer
                            .parseInt(layout.getTag().toString());
                    Intent intent = new Intent(getApplicationContext(),
                            OtherUsersProfileActivity.class);
                    intent.putExtra("name", comments.get(position)
                            .getCusername());
                    intent.putExtra("id", comments.get(position).getCuserid());
                    startActivity(intent);
                }
            });
    txtview_commentusername_commentitem
            .setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    int index = Integer
                            .parseInt(layout.getTag().toString());
                    Intent intent = new Intent(getApplicationContext(),
                            OtherUsersProfileActivity.class);
                    intent.putExtra("name", comments.get(index)
                            .getCusername());
                    intent.putExtra("id", comments.get(index).getCuserid());
                    startActivity(intent);
                }
            });
    layout.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            return false;
        }
    });
    layout.invalidate();
    layout_commentsList_container_PostActivity.invalidate();
    layout_commentsList_container_PostActivity.addView(layout);
    layout_commentsList_container_PostActivity.invalidate();    
    findViewById(android.R.id.content).invalidate();
}

i try

findViewById(android.R.id.content).invalidate();
layout.invalidate();
layout_commentsList_container_PostActivity.invalidate();

but no changes

See this pic and help please enter image description here

mostafa hashim
  • 360
  • 1
  • 5
  • 24

1 Answers1

0

as this answer https://stackoverflow.com/a/24629341/3739429 i Create Custom ListView Which is non Scrollable

 public class NonScrollListView extends ListView {

public NonScrollListView(Context context) {
    super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();    
}
} 
Community
  • 1
  • 1
mostafa hashim
  • 360
  • 1
  • 5
  • 24