如何获得一个特定的选定行的行ID? [英] How to get the row id of a particular selected row?
问题描述
我已经添加了两个 TableRows
到 TableLayout
这是一个循环。在每月的第一个的TableRow
有6个 TextViews
1 的ImageView
&安培; 1切换按钮。我添加了一个 OnClickListener
到第一行
&安培;切换按钮。我的问题是在为的onclick
方法第一行
,我应该怎么弄那个特定的选行的行ID ?
I have added two TableRows
to TableLayout
that is in a for loop. In every first TableRow
there are 6 TextViews
and 1 ImageView
& 1 Toggle Button. I have added an OnClickListener
to the first row
& Toggle Button. My question is in the onclick
method for the First Row
, how should I get the row id of that particular selected row?
有人能帮助我吗?
PLZ帮我.....
Plz help me.....
我希望得到一个特定的选行的行ID ......
I want to get the row id of a particular selected row......
PLZ有人回复了我......
Plz anyone reply me....
推荐答案
通过在的ImageView的
查看
层次导航 OnCLickListener
是这样的:
Navigate through the View
hierarchy in the ImageView
OnCLickListener
like this:
imageView.setOnClickListener(new OnClickListener() {
public void onCLick(View v) {
// v represents the view that was clicked(the ImageView)
// if the ImageView is added directly to the TableRow then you could simply do
TableRow tr = (TableRow) v.getParent(); // if the ImageView isn't a direct child of the TableRow then walk through all the parent with getParent().
// do stuff
}
});
编辑:
您code没有帮助,并通过看你做什么,我会建议你先从简单的东西一点点地了解Android。此外, tabLayout.addView(openedRow1,n_D);
标签不添加到的 openedRow1 的查看
(如果这是你想做的事),它只是立场查看
在父的具体位置(如 0
是父母的第一个孩子)。
Your code doesn't help and by looking at what you're doing I would advise you to start with something a little simpler to learn about android. Also, tabLayout.addView(openedRow1, n_D);
doesn't add a tag to the openedRow1 View
(if this is what you want to do), it just position that View
to the specific position in the parent(like 0
to be the first child of the parent).
我猜,你想从第二个的TextView
( tv_vin_val ?!?!)时,它的母公司是文本点击。如果这一切你想做的事然后尝试这样的事:
I would guess that you're trying to get the text from the second TextView
( tv_vin_val ?!?!) when it's parent is clicked. If this is all you want to do then try something like this:
public void onClick(View v) {
// you set the listener on the TableRow so v is the TableRow that was clicked
TableRow lTableRow = ((TableRow) v);
// to get the TextView use getChildAt or findViewById
TextView lTextView = (TextView)lTableRow.getChildAt(1);
//get the text from the TextView
vinNum = lTextView.getText().toString();
// the tag
int theTag = (Integer) v.getTag();
Intent intent = new Intent(DeliveryInspectionActivity.this, ExceptionsActivity.class);
//intent.putExtra("row id value", theTag);
startActivityForResult(intent, 0);
}
这篇关于如何获得一个特定的选定行的行ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!