我目前在 android 中有一个表格布局。这被设置为时间表,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadeScrollbars="false" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/blank"
android:background="@drawable/border" />
<TextView
android:id="@+id/mon"
android:background="@drawable/border"
android:text="@string/monday" />
<TextView
android:id="@+id/tues"
android:background="@drawable/border"
android:text="@string/tuesday" />
<TextView
android:id="@+id/wed"
android:background="@drawable/border"
android:text="@string/wednesday" />
<TextView
android:id="@+id/thurs"
android:background="@drawable/border"
android:text="@string/thursday" />
<TextView
android:id="@+id/fri"
android:background="@drawable/border"
android:text="@string/friday" />
<TextView
android:id="@+id/sat"
android:background="@drawable/border"
android:text="@string/Saturday" />
<TextView## Heading ##
android:id="@+id/sun"
android:background="@drawable/border"
android:text="@string/Sunday" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/nine"
android:background="@drawable/border"
android:text="@string/nine" />
<TextView
android:id="@+id/nineone"
android:background="@drawable/border" />
<TextView
android:id="@+id/ninetwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/ninethree"
android:background="@drawable/border" />
<TextView
android:id="@+id/ninefour"
android:background="@drawable/border" />
<TextView
android:id="@+id/ninefive"
android:background="@drawable/border" />
<TextView
android:id="@+id/ninesix"
android:background="@drawable/border" />
<TextView
android:id="@+id/nineseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/ten"
android:background="@drawable/border"
android:text="@string/ten" />
<TextView
android:id="@+id/tenone"
android:background="@drawable/border" />
<TextView
android:id="@+id/tentwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/tenthree"
android:background="@drawable/border" />
<TextView
android:id="@+id/tenfour"
android:background="@drawable/border" />
<TextView
android:id="@+id/tenfive"
android:background="@drawable/border" />
<TextView
android:id="@+id/tensix"
android:background="@drawable/border" />
<TextView
android:id="@+id/tenseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/eleven"
android:background="@drawable/border"
android:text="@string/eleven" />
<TextView
android:id="@+id/elevenone"
android:background="@drawable/border" />
<TextView
android:id="@+id/eleventwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/eleventhree"
android:background="@drawable/border" />
<TextView
android:id="@+id/elevenfour"
android:background="@drawable/border" />
<TextView
android:id="@+id/elevenfive"
android:background="@drawable/border" />
<TextView
android:id="@+id/elevensix"
android:background="@drawable/border" />
<TextView
android:id="@+id/elevenseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/twelve"
android:background="@drawable/border"
android:text="@string/twelve" />
<TextView
android:id="@+id/twelveone"
android:background="@drawable/border" />
<TextView
android:id="@+id/twelvetwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/twelvethree"
android:background="@drawable/border" />
<TextView
android:id="@+id/twelvefour"
android:background="@drawable/border" />
<TextView
android:id="@+id/twelvefive"
android:background="@drawable/border" />
<TextView
android:id="@+id/twelvesix"
android:background="@drawable/border" />
<TextView
android:id="@+id/twelveseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/one"
android:background="@drawable/border"
android:text="@string/one" />
<TextView
android:id="@+id/oneone"
android:background="@drawable/border" />
<TextView
android:id="@+id/onetwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/onethree"
android:background="@drawable/border" />
<TextView
android:id="@+id/onefour"
android:background="@drawable/border" />
<TextView
android:id="@+id/onefive"
android:background="@drawable/border" />
<TextView
android:id="@+id/onesix"
android:background="@drawable/border" />
<TextView
android:id="@+id/oneseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/two"
android:background="@drawable/border"
android:text="@string/two" />
<TextView
android:id="@+id/twoone"
android:background="@drawable/border" />
<TextView
android:id="@+id/twotwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/twothree"
android:background="@drawable/border" />
<TextView
android:id="@+id/twofour"
android:background="@drawable/border" />
<TextView
android:id="@+id/twofive"
android:background="@drawable/border" />
<TextView
android:id="@+id/twosix"
android:background="@drawable/border" />
<TextView
android:id="@+id/twoseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/three"
android:background="@drawable/border"
android:text="@string/three" />
<TextView
android:id="@+id/threeone"
android:background="@drawable/border" />
<TextView
android:id="@+id/threetwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/threethree"
android:background="@drawable/border" />
<TextView
android:id="@+id/threefour"
android:background="@drawable/border" />
<TextView
android:id="@+id/threefive"
android:background="@drawable/border" />
<TextView
android:id="@+id/threesix"
android:background="@drawable/border" />
<TextView
android:id="@+id/threeseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/four"
android:background="@drawable/border"
android:text="@string/four" />
<TextView
android:id="@+id/fourone"
android:background="@drawable/border" />
<TextView
android:id="@+id/fourtwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/fourthree"
android:background="@drawable/border" />
<TextView
android:id="@+id/fourfour"
android:background="@drawable/border" />
<TextView
android:id="@+id/fourfive"
android:background="@drawable/border" />
<TextView
android:id="@+id/foursix"
android:background="@drawable/border" />
<TextView
android:id="@+id/fourseven"
android:background="@drawable/border" />
</TableRow>
<TableRow
android:id="@+id/tableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/five"
android:background="@drawable/border"
android:text="@string/five" />
<TextView
android:id="@+id/fiveone"
android:background="@drawable/border" />
<TextView
android:id="@+id/fivetwo"
android:background="@drawable/border" />
<TextView
android:id="@+id/fivethree"
android:background="@drawable/border" />
<TextView
android:id="@+id/fivefour"
android:background="@drawable/border" />
<TextView
android:id="@+id/fivefive"
android:background="@drawable/border" />
<TextView
android:id="@+id/fivesix"
android:background="@drawable/border" />
<TextView
android:id="@+id/fiveseven"
android:background="@drawable/border" />
</TableRow>
</TableLayout>
</ScrollView>
当用户单击应用程序中的单元格时,我希望能够获得他们单击的确切单元格的位置。我得到了列 id,但我无法得到完整的位置。我的代码如下
public class TimeTable extends Activity {
TextView tv;
TableRow row;
String dayName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_table);
TableLayout group = (TableLayout) findViewById(R.id.table);
row = (TableRow) group.getChildAt(0);
for (int i = 0; i < group.getChildCount(); i++) {
row = (TableRow) group.getChildAt(i);
for (int j = 0; j < row.getChildCount(); j++) {
tv = (TextView) row.getChildAt(j);
registerForContextMenu(tv);
tv.setId(j);
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast toast = Toast.makeText(getApplicationContext(), Integer.toString(v.getId()), Toast.LENGTH_LONG);
toast.show();
}
});
}
}
}
有谁知道我怎样才能获得完整的职位?谢谢