好吧,所以我一直在努力通过浏览帖子来解决这个问题,但我还没有遇到任何可行的东西。
这是我的表格代码的一部分:
TableLayout flightInfoTable = (TableLayout) findViewById(R.id.flightInfoTable);
flightInfoTable.setStretchAllColumns(true);
flightInfoTable.setShrinkAllColumns(true);
for (int i = 16; i < flightInfoArrayLenght - 1; i++) {
TableRow rowFlightInfo = new TableRow(this);
rowFlightInfo.setGravity(Gravity.CENTER);
rowFlightInfo.setPadding(5, 10, 5, 10);
TableRow.LayoutParams params = new TableRow.LayoutParams();
params.width = -2;
rowFlightInfo.setLongClickable(true);
registerForContextMenu(rowFlightInfo);
TextView tvTerminal = new TextView(this);
tvTerminal.setGravity(Gravity.CENTER);
tvTerminal.setText(flightInfoArray[i][6]);
rowFlightInfo.addView(tvTerminal, params);
etc.. etc..
flightInfoTable.addView(rowFlightInfo);
}
和上下文菜单:
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
menu.setHeaderTitle(".....");
inflater.inflate(R.menu.context_startmenu, menu);
}
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.contextmenu_option1:
//stuff
return true;
default:
return super.onContextItemSelected(item);
}
}
所以基本上我需要在选定的(长按并打开上下文菜单)表行中获取文本视图中的值。
有什么想法和建议吗?
非常感谢您的帮助!