在ContextMenu中获取表行数据 [英] Get Table Row data in the ContextMenu

查看:106
本文介绍了在ContextMenu中获取表行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我现在已经苦苦挣扎了一段时间,以找出浏览帖子的方法,但是我还没有发现任何可行的方法.

Well so I've been struggling for a while now to figure this out browsing through posts but I haven't yet come across anything viable.

这是我的表格代码的一部分:

This is a part of my code for the table:

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

因此,基本上,我需要在选定的(长按&上下文菜单已打开)表行的textviews中获取值.

So basically I need to get the values in textviews in the selected (long clicked & context menu opened) table row.

有什么想法和建议吗?

非常感谢您的帮助!

推荐答案

我实际上已经弄清楚了,所以这是该表的新代码:

I figured it out actually, so here's the new code for the table:

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

rowFlightInfo.setOnLongClickListener(new OnLongClickListener() {

                 @Override
                        public boolean onLongClick(View v) {
                          String flightNumber = tvFlight.getText().toString();
                          flightNumber = flightNumber.replaceAll("\\s", "");
                          setIntent(getIntent().putExtra("flightNumber", flightNumber));
                          setIntent(getIntent().putExtra("flightInfo", "From " + tvFrom.getText() + " to Colombo"));
                          registerForContextMenu(v);
                          openContextMenu(v);
                          unregisterForContextMenu(v);
                          return true;
                        }
                      });

}

&然后从您想要的任何地方检索意图,这只是通常的检索意图的基本方法:

& then to retrieve the intent from where ever you want of course, just the usual basic way to retrieve any intent:

Intent intent = getIntent();

     final String flightNumber = intent.getStringExtra("flightNumber");
     final String flightInfo = intent.getStringExtra("flightInfo");

这篇关于在ContextMenu中获取表行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆