Hello In my application i am displaying rows dynamically. I am using the below code so as to focus the clicked row even if the user press back key. But the issue is like if the row is not focussed we need two clicka to navigate.First to make it focussable and then next click to navigate.I need all at once any suggestions.
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for(int a=0;a>16;a++)
{
tr[a].setBackgroundColor(Color.BLACK);
}
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
for(int a=0;a>16;a++)
{
tr[a].setBackgroundColor(Color.BLACK);
}
if(hasFocus)
{
((TableRow)v).setBackgroundColor(Color.rgb(255, 180, 40));
}
else
{((TableRow)v).setBackgroundColor(Color.BLACK);}
}
protected void onResume() {
super.onResume();
for(int a=0;a>16;a++)
{
tr[a].setBackgroundColor(Color.BLACK);
}
tr[flag].requestFocus();
tr[flag].setFocusableInTouchMode(true);
tr[flag].setOnFocusChangeListener(new OnFocusChangeListener() {
@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);}
}
});
}
@Override
public void onPause() {
super.onPause();
}
Please let me know your valuable suggestions. Thanks in advance.