开发者

How to get tablerow id dynamically in android?

Hello, my old code is working, but the problem is that when i am clicking tablerow it call another activty, but it not set that table row data but it setting last array data to that activity.

Means it set the last array value to next screen activity.

for ( j = 0; j < dataListfeture.size(); j++)
            {

                HashMap<String, String> hm = new HashMap<String, String>();

                hm = dataListfeture.get(j);

                final TableRow tblrow = new TableRow(MainScreen.this);
                final View rowView = inflater.inflate(R.layout.featuredrow, null);
                tblrow.setId(j);
                tblrow.getId();



                featuredName = (TextView) rowView.findViewById(R.id.xxName);
                featuredDistance = (TextView) rowView.findViewById(R.id.xxDistance);
                featuredVeneType = (TextView) rowView.findViewById(R.id.xxVeneType);
                featuredPhone = (TextView) rowView.findViewById(R.id.xxPhone);
                featuredAddress = (TextView) rowView.findViewById(R.id.xxAddress);

                Drawable image = ImageOperations(MainScreen.this, hm.get("url"), "image.jpg");

                featuredImage = (ImageView) rowView.findViewById(R.id.xxdImage);
                featuredImage.setImageDrawable(image);

                featuredName.setText("" + hm.get("name"));
                featuredDistance.setText("" + hm.get("distance") + " mi");
                featuredVeneType.setText("" + hm.get("venuetype"));
                featuredPhone.setText("" + hm.get("phonenumber"));
                featuredAddress.setText("" + hm.get("address"));


                mapnamelist = hm.get("name");
                mapvenuelist = hm.get("venuetype");
                mapothervenuelist  = hm.get("othervenuetype");
                mapaddresslist= hm.get("address");
                mapcitylist= hm.get("city");
                mapstatelist= hm.get("state");


                tblrow.setOnClickListener(new OnClickListener() 
                {

                    @Override
                    public void onClick(View v) 
                    {

                        final ProgressDialog progDailog = ProgressDialog.show(MainScreen.this, null, "Loading ....", true);
                        final Handler handler = new Handler()
                        {
                            public void handleMessage(Message msg)
                            {
                                System.out.println("search");

                                Intent myIntent = new Intent(MainScreen.this, xxxxscreen.class);
                                startActivity(myIntent);
                                MainScreen.this.finish();
                                progDailog.dismiss();

                            }
                        };

                        new Thread()
                        {
                            public void run()
                            {
                                try
                                {

                                    System.out.println();


                                    handler.sendEmptyMessage(1);

                                }
                                catch (Exception e)
                                {
                                  开发者_如何学编程  e.printStackTrace();
                                }
                            }
                        }.start();

                    }
                });


Create an int array of id say array_id[] and after setting id to table row add that id to array_id[] also like

tblrow.setId(j);
array_id[j] = j;

And in onClick method do this:

for(int i = 0;i< array_id.length;i++)
{
    TableRow tbl_row = (TableRow) findViewById(i);
    if(v.getId() == array_id[i])
    {
        /**    Perform your Operations */
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜