title: How to get id to INFLATED view in android?
body: <p>here i make the horizontal animating listview where i am customizing view by using list_view.xml </p>
  
  <p>i am inflate it for  making the custom component. It's work properly  assign  id to every custom component but i am not able to get it by getId method.</p>
  
  <pre><code>    package com.example.animationdemo;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.Context;
  import android.os.Bundle;
  import android.util.DisplayMetrics;
  import android.util.Log;
  import android.view.Display;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.animation.Animation;
  import android.view.animation.Animation.AnimationListener;
  import android.view.animation.TranslateAnimation;
  import android.widget.ImageView;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  @SuppressLint("NewApi")
  public class MainActivity extends Activity implements AnimationListener,
          OnClickListener {
  
      Animation anim;
      LinearLayout myLayout;
      ImageView myImage;
  
      private static int a = 1000;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myLayout = (LinearLayout) findViewById(R.id.myLayout);
  
          myImage = (ImageView) findViewById(R.id.imageView1);
          String[] myString = { "sam", "man", "van", "can", "man", "van", "can",
                  "man", "van", "can", "man", "van", "can", "man", "van", "can",
                  "man", "van", "can", "man", "van", "can", "man", "van", "can",
                  "man", "van", "1234" };
          for (String string : myString) {
              View view = new View(this);
              view = inflateEditRow(string);
              view.setOnClickListener(this);
              Log.i("Law", "Id val " + a);
              view.setId(++a);
              myLayout.addView(view);
          }
      }
  
      private View inflateEditRow(String string) {
          LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View row = inflater.inflate(R.layout.list_view, myLayout, false);
          TextView tv = (TextView) row.findViewById(R.id.TextView1);
          tv.setText(string);
          Log.i("Law", "string " + row.getId());
          return row;
      }
  
      @Override
      protected void onStart() {
          // TODO Auto-generated method stub
          super.onStart();
  
          /*
           * anim = AnimationUtils .loadAnimation(MainActivity.this,
           * R.anim.animation); anim.setRepeatCount(3); anim.setDuration(30000);
           * myLayout.startAnimation(anim); anim.setAnimationListener(this);
           */
          Log.i("myLayout", "string " + myLayout.getWidth());
          Display display = getWindowManager().getDefaultDisplay();
          @SuppressWarnings("deprecation")
          int stageWidth = display.getWidth();
          Log.i("stageWidth", " " + stageWidth);
          anim = new TranslateAnimation(stageWidth, -28 * dpToPx(200), 0, 0);
          anim.setDuration(2000 * 28);
          // anim.setInterpolator(MainActivity.this,1);
          anim.setFillAfter(true);
          myLayout.startAnimation(anim);
          anim.setAnimationListener(this);
          myLayout.setVisibility(1);
      }
  
      @Override
      public void onAnimationEnd(Animation animation) {
          myLayout.startAnimation(anim);
          Toast.makeText(getApplicationContext(), "Animation End",
                  Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onAnimationRepeat(Animation animation) {
          // Toast.makeText(getApplicationContext(), "Animation Repeat",
          // Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onAnimationStart(Animation animation) {
          // Toast.makeText(getApplicationContext(), "Animation Start",
          // Toast.LENGTH_SHORT).show();
      }
  
      /*
       * private View inflateEditRow(String string) { LayoutInflater inflater =
       * (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View
       * row = inflater.inflate(R.layout.list_view, myLayout, false); TextView tv
       * = (TextView) row.findViewById(R.id.TextView1); tv.setText(string);
       * Log.i("Law", "string " + row.getId()); return row; }
       */
  
      public int dpToPx(int dp) {
          DisplayMetrics displayMetrics = getBaseContext().getResources()
                  .getDisplayMetrics();
          int px = dp
                  * Math.round((displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
          Toast.makeText(getApplicationContext(),
                  "displayMetrics.xdpi" + displayMetrics.xdpi, Toast.LENGTH_SHORT)
                  .show();
          return px;
      }
  
      @SuppressLint("ShowToast")
      @Override
      public void onClick(View v) {
  
          Toast.makeText(getApplicationContext(), "Sumant" + v.getId(), 10)
                  .show();
  
      }
  }
  enter code here
  </code></pre>
  
  <p>This is my activity_main.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="50000dp"
      android:layout_height="fill_parent"
      tools:context=".MainActivity"
      android:orientation="vertical"
      android:id="@+id/mainLayout" &gt;
  
     &lt;LinearLayout
          android:id="@+id/myLayout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="horizontal" &gt;
  
      &lt;/LinearLayout&gt;
  
     &lt;ImageView
         android:id="@+id/imageView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/ic_launcher" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This is my list_View.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal" &gt;
  
      &lt;TableLayout
          android:layout_width="200dp"
          android:layout_height="wrap_content"
          android:background="#FF9900" &gt;
  
          &lt;TableRow
              android:id="@+id/tableRow1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" &gt;
  
              &lt;TableLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" &gt;
  
                  &lt;TableRow
                      android:layout_width="30dp"
                      android:layout_height="40dp" &gt;
  
                      &lt;ImageView
                          android:id="@+id/imageView1"
                          android:layout_width="30dp"
                          android:layout_height="30dp"
                          android:background="#3366FF"
                          android:src="@drawable/ic_launcher" /&gt;
                  &lt;/TableRow&gt;
  
                  &lt;TableRow
                      android:layout_width="30dp"
                      android:layout_height="40dp" &gt;
  
                      &lt;ImageView
                          android:id="@+id/imageView2"
                          android:layout_width="30dp"
                          android:layout_height="30dp"
                          android:background="#FFFF99"
                          android:src="@drawable/ic_launcher" /&gt;
                  &lt;/TableRow&gt;
              &lt;/TableLayout&gt;
  
              &lt;TextView
                  android:id="@+id/TextView1"
                  android:layout_width="100dp"
                  android:layout_height="60dp"
                  android:background="#CC33FF"
                  android:gravity="center"
                  android:padding="10dip"
                  android:text="NMDC sdas dsfsdf"
                  android:textColor="#ffffff"
                  android:textSize="12sp" /&gt;
  
              &lt;TableLayout
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" &gt;
  
                  &lt;TableRow
                      android:layout_width="70dp"
                      android:layout_height="40dp"
                      android:layout_weight="0.5"
                      android:background="#d0000c" &gt;
  
                      &lt;TextView
                          android:id="@+id/TextView11"
                          android:layout_width="70dp"
                          android:layout_height="30dp"
                          android:gravity="center"
                          android:paddingBottom="8dip"
                          android:paddingTop="8dip"
                          android:text="10000.00"
                          android:textColor="#ffffff"
                          android:textSize="12sp" /&gt;
                  &lt;/TableRow&gt;
  
                  &lt;TableRow
                      android:layout_width="wrap_content"
                      android:layout_height="30dp"
                      android:layout_weight="0.5" &gt;
  
                      &lt;TableLayout&gt;
  
                          &lt;TableRow
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_weight="1" &gt;
  
                              &lt;TextView
                                  android:id="@+id/TextView21"
                                  android:layout_width="30dp"
                                  android:layout_height="30dp"
                                  android:layout_weight="1"
                                  android:background="#d0dc0c"
                                  android:gravity="center"
                                  android:paddingBottom="8dip"
                                  android:paddingTop="8dip"
                                  android:text="Row"
                                  android:textColor="#ffffff"
                                  android:textSize="12sp" /&gt;
  
                              &lt;TextView
                                  android:id="@+id/TextView22"
                                  android:layout_width="40dp"
                                  android:layout_height="30dp"
                                  android:layout_weight="1"
                                  android:background="#6600FF"
                                  android:gravity="center"
                                  android:paddingBottom="8dip"
                                  android:paddingTop="8dip"
                                  android:text="100%"
                                  android:textColor="#ffffff"
                                  android:textSize="12sp" /&gt;
                          &lt;/TableRow&gt;
                      &lt;/TableLayout&gt;
                  &lt;/TableRow&gt;
              &lt;/TableLayout&gt;
          &lt;/TableRow&gt;
      &lt;/TableLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>