title: Updating Layout of a row in ListView when OnClick event is called
body: <p>I have a ListView in which there is a TextView and a custom view in which I am drawing a rectangle. I want a functionality that when a row of ListView is clicked, the rectangle should become bigger but other row's rectangle should remain in its previous shape. </p>
  
  <p>So first I am increasing width and height of layout and then trying to increase the rectangle size after that but although my onDraw() method is called when I am clicking the listener but size of rectangle is not increasing.</p>
  
  <p>Also my onDraw() method of DrawView is called infinitely even though I am clicking only once
  Can anyone help me out.</p>
  
  <p>DrawView.java, which is used for making making rectangle</p>
  
  <pre><code>public class DrawView extends View {
      Paint paint = new Paint();
      public int x=-1;   // this variable will tell 
  
      public DrawView(Context context) {
          this(context, null);            
      }
  
      public DrawView(Context context, AttributeSet attrs) {
          this(context, attrs, 0);
      }
  
      public DrawView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
      }
  
      @Override
      public void onDraw(Canvas canvas) {
          paint.setStrokeWidth(10);
          paint.setColor(Color.MAGENTA);
          Log.e("Ronak","onDraw  "+x);
  
          canvas.drawRect(0, 0, 300, 200, paint );
          if(x&gt;=0)  //this method is not called for first view but is called for onClickListener
          {
              increase(canvas);
          }
  
  
      }
  
      private void increase(Canvas canvas) {
          Log.e("Ronak","Increase");
          canvas.drawRect(0, 0, 700, 800, paint );
  
      }
  
  
  
  
  }
  </code></pre>
  
  <p>My getView() function for custom ListView</p>
  
  <pre><code>        public View getView(final int position,  View convertView, final ViewGroup parent) {
          ViewHolder holder = null;
          if (convertView == null) {
                          holder = new ViewHolder();
                          convertView = mInflater.inflate(R.layout.news_list_item,null);
                          final LinearLayout layout = (LinearLayout)convertView.findViewById(R.id.mainLayout);
                             TextView t= (TextView)convertView.findViewById(R.id.textView1);
                          holder.textview = t;
                          holder.ll=layout;
                          final DrawView abc = (DrawView)convertView.findViewById(R.id.drawview);
                          holder.drawview=abc;
                          Log.e("Ronak","reached here3");            
                          convertView.setTag(holder);
          } else {
              holder = (ViewHolder)convertView.getTag();
          }
          holder.textview.setText(mData.get(position));
  
  
          convertView.setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
               Toast.makeText(c, "Clicked on="+position, 2).show();
               ViewHolder mH = (ViewHolder) v.getTag();
               LinearLayout.LayoutParams pp = new LinearLayout.LayoutParams(500,400);
               mH.ll.setLayoutParams(pp);
               DrawView dd=mH.drawview;
               dd.x=position;
               dd.invalidate();
                  }
          });
  
          return convertView;
  
  
  
      }
  
       static class ViewHolder {
              public DrawView drawview;
              public TextView textview;
              public LinearLayout ll;
          } 
  </code></pre>
  
  <p>and my layout file for each row of ListView</p>
  
  <pre><code>    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/mainLayout"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:padding="2dp" &gt;
  
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="50dp"
          android:layout_height="30dp"
          android:text="Text"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
      &lt;com.krish.horizontalscrollview.DrawView
          android:id="@+id/drawview"
          android:layout_width="150dp"
          android:layout_height="100dp" &gt;
      &lt;/com.krish.horizontalscrollview.DrawView&gt;
  
  &lt;/LinearLayout&gt; 
  </code></pre>
  
  <p>My ListView class</p>
  
  <pre><code>    public class CenterLockHorizontalScrollview extends HorizontalScrollView {
      Context context;
      int prevIndex = 0;
  
      public CenterLockHorizontalScrollview(Context context, AttributeSet attrs) {
          super(context, attrs);
          this.context = context;
          this.setSmoothScrollingEnabled(true);
  
      }
  
  
  
      public void setAdapter(Context context, CustomListAdapter mAdapter) {
  
          try {
              fillViewWithAdapter(mAdapter);
          } catch (ZeroChildException e) {
  
              e.printStackTrace();
          }
      }
  
      private void fillViewWithAdapter(CustomListAdapter mAdapter)
              throws ZeroChildException {
          if (getChildCount() == 0) {
              throw new ZeroChildException(
                      "CenterLockHorizontalScrollView must have one child");
          }
          if (getChildCount() == 0 || mAdapter == null)
              return;
  
          ViewGroup parent = (ViewGroup) getChildAt(0);
  
          //parent.removeAllViews();
  
          for (int i = 0; i &lt; mAdapter.getCount(); i++) {
              parent.addView(mAdapter.getView(i, null, parent));
          }
      }
  </code></pre>