I am developing a sample application for testing OnFocusChangeListener, I left the debugging point in the method public void onFocusChange(View v, boolean hasFocus), and I noticed that the method is called only once, i.e. after starting the application, up to this it is fine, but when I scroll down to the next element of the list, the object was focused, but the method is not called. I know that I am missing a little. could you help me get rid of this problem. Thanks in advance.
Note Scrolling is done using the D-Pad.
java class:
package com.example.listview;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ListActivity extends Activity implements OnFocusChangeListener{
String[] items={"iOS","android","Symbian",};
ListView lst;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
lst=(ListView)findViewById(R.id.listView1);
lst.setFocusableInTouchMode(false);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1,items);
lst.setAdapter(adapter);
}
public void onFocusChange(View v, boolean hasFocus) {
Toast.makeText(getBaseContext(), "FOCUSED", Toast.LENGTH_LONG).show();
}
}
source
share