button.setId(integer value) gives me view error

admin

Administrator
Staff member
Hi all i have implemented my customized simpleCursorAdapter and its view merged with another view to create my desired page but when i try to set id to each button of my list view's record than it is giving me an view error

Half of the logic is from this link:

<a href="http://thinkandroid.wordpress.com/2...010/01/09/simplecursoradapters-and-listviews/" rel="nofollow">http://thinkandroid.wordpress.com/2010/01/09/simplecursoradapters-and-listviews/</a>

and other part of code of my customize view is given below:

Code:
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        setContentView(R.layout.fr1);


        Cursor c = getContentResolver().query(People.CONTENT_URI,
                null, null, null, null);
                startManagingCursor(c);
                String[] cols = new String[]{People.NAME};
                int[] names = new int[]{R.id.FriendsName};

        SimpleCursorAdapter rows = new MyAdapter(this,R.layout.flistview,c,cols,names);
        setListAdapter(rows);           
    }

public class MyAdapter extends SimpleCursorAdapter{

        public DisplayFriendsAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);
        }

        public View getView(int position, View convertView, ViewGroup parent){
            View view = super.getView(position, convertView, parent);
            ImageButton Btn1 = (ImageButton)view.findViewById(R.id.Button1);
            Btn1.setId(position);
            ImageButton Btn2 = (ImageButton)view.findViewById(R.id.Button2);
            Btn2.setId(position);
            Btn1.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Log.i("Accepted", "clicked"+v.getId());

                }
            }); 

            Btn2.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {


                }
            }); 
            return view;
        }
    }