在android中回按键码

Rem*_*van 4 android

在我的 android 应用程序中,我有三个页面 A、B、C。所有这三个页面都有表格布局。如果我点击特定行,将显示与该行相关的其他页面。现在我需要的是,如果一个人在第二页之后点击返回,我需要关注他在返回时在第一页点击的那一行。我可以在 android 中执行此操作吗?请回复您的宝贵建议。

Totramonhave 建议后我的代码是。

在 amy 代码中,我动态生成行。

public void onClick(View v) {
    // TODO Auto-generated method stub
    flag=v.getId();
    if(v.getId()==1)
    {
        Intent i = new Intent(TableImageLayout.this, TableImageLayout3.class);
        startActivity(i);

    }
    if(v.getId()==3)
    {
        Intent i = new Intent(TableImageLayout.this, TableImageLayout3.class);
        startActivity(i);

    }
    if(v.getId()==5)
    {
        Intent i = new Intent(TableImageLayout.this, TableImageLayout3.class);
        startActivity(i);
    }

    if(v.getId()==7)
    {
        Intent i = new Intent(TableImageLayout.this, TableImageLayout3.class);
        startActivity(i);
    }

    if(v.getId()==100)
    {
        Intent i = new Intent(TableImageLayout.this, TableImageLayout3.class);
        startActivity(i);
    }   

}



@Override
public void onFocusChange(View v, boolean hasFocus) {
    // TODO Auto-generated method stub

        if(hasFocus)
    {
        ((TableRow)v).setBackgroundColor(Color.rgb(255, 180, 40));
    }
    else
        {((TableRow)v).setBackgroundColor(Color.BLACK);}

}
    protected void onResume() { 
        super.onResume();
        tr[flag].requestFocus();
        tr[flag].setFocusableInTouchMode(true);
        if(tr[flag].hasFocus())
        {
            tr[flag].setBackgroundColor(Color.rgb(255, 180, 40));
        }
        else
            {tr[flag].setBackgroundColor(Color.BLACK);}
    }



     @Override   
     public void onPause() {      
    super.onPause();        

     }
Run Code Online (Sandbox Code Playgroud)

提前致谢 :)

DeR*_*gan 5

你可以试试这个

public boolean onKeyDown(int keyCode, KeyEvent event) 
{       
  if(keyCode==KeyEvent.KEYCODE_BACK)

          {
            //Your code here
          }
    }
Run Code Online (Sandbox Code Playgroud)