如何在android中动态获取tablerow id?

时间:2011-08-10 09:57:43

标签: android

您好,我的旧代码正在运行,但问题是,当我点击tablerow时,它会调用另一个activty,但它没有设置该表行数据,但它将最后一个数组数据设置为该活动。

表示将最后一个数组值设置为下一个屏幕活动。

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();

                    }
                });

1 个答案:

答案 0 :(得分:1)

创建一个int数组,标识为array_id[],在将ID设置为表格行之后,将该ID添加到array_id[]也像

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

在onClick方法中执行此操作:

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

}