单击事件发生后如何使按钮不失去焦点

时间:2019-01-25 05:40:53

标签: javascript java google-chrome internet-explorer gwt

在Java中,我用一个选择框(doclistbox)和一个button(openbutton)元素创建了一个页面,“ doclistbox”用于选择文档,“ openbutton”用于打开所选文档,并且我将这两个元素的tabindex设置为像这样2以便于访问

public class GridViewActivity extends AppCompatActivity {
    Context context=GridViewActivity.this;
    RecyclerView recyclerView;
    int PICK_IMAGE_MULTIPLE=1;
    static ArrayList<Images> arrayList;
    static ImagesAdapter imagesAdapter;
    AutoFitGridLayoutManager autoFitGridLayoutManager;
    SharedPref sharedPref;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_view);
        recyclerView=findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);
        autoFitGridLayoutManager=new AutoFitGridLayoutManager(context,250);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setLayoutManager(autoFitGridLayoutManager);

        arrayList=new ArrayList<>();                        // move this line above adapter initialization
        imagesAdapter=new ImagesAdapter(context,arrayList);

        setRecyclerView();                               // forgot to invoke this method here. 

        sharedPref=new SharedPref(context);
        if (sharedPref.getCount()==0) {
            Toast.makeText(context, "No images...", Toast.LENGTH_SHORT).show();
        }
        else {
            Gson gson=new Gson();
            String response=sharedPref.getImages();
            arrayList=gson.fromJson(response,new TypeToken<ArrayList<Images>>(){}.getType());
            Log.d("ROHIT", String.valueOf(arrayList.size()));
            imagesAdapter.notifyDataSetChanged();    // change is here
        }
    }

    public void setRecyclerView() {
        ItemTouchHelper.Callback callback=new ItemMoveCallback(imagesAdapter);
        ItemTouchHelper touchHelper=new ItemTouchHelper(callback);
        touchHelper.attachToRecyclerView(recyclerView);
        recyclerView.setAdapter(imagesAdapter);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId()==R.id.add_imges_cam) {
            //open camera
        }
        else if(item.getItemId()==R.id.add_imges_gallery) {
            //open gallery to select images
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_IMAGE_MULTIPLE);
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        int count=0;
        if(requestCode==PICK_IMAGE_MULTIPLE && resultCode==RESULT_OK) {
            String[] filePath = {MediaStore.Images.Media.DATA};

            if (data.getData() != null) {
                //if single image is selected
                Uri imageUri = data.getData();
                Cursor cursor = getContentResolver().query(imageUri, filePath, null, null, null);
                cursor.moveToFirst();
                arrayList.add(new Images(imageUri.toString()));
                cursor.close();
            } else {
                if (data.getClipData() != null) {
                    ClipData mClipData = data.getClipData();
                    for (int i = 0; i < mClipData.getItemCount(); i++) {
                        ClipData.Item item = mClipData.getItemAt(i);
                        Uri uri = item.getUri();
                        // Get the cursor
                        Cursor cursor = getContentResolver().query(uri, filePath, null, null, null);
                        // Move to first row
                        cursor.moveToFirst();
                        arrayList.add(new Images(uri.toString()));
                        count++;
                        cursor.close();
                    }
                }
            }

            sharedPref.save(arrayList);
            Log.d("ROHIT","data saved arraylist"+arrayList.size());
            sharedPref.updateCount(count);
            Log.d("ROHIT","data saved");
            imagesAdapter.notifyDataSetChanged();
        }
    }

}

并且我还为打开按钮设置了快捷键

docWidgetObj.docListBox.setTabIndex(2);
docWidgetObj.openButton.setTabIndex(2);
  

现在,要求仅在以下位置使用这些功能:   没有鼠标的键盘,所以当我尝试在Tab和Shift + Tab之间进行切换时   打开文档后,这两个打开按钮失去了焦点   基本上是失去了控制。

注意:它不会在IE中失去焦点,只是在chrome中失去了焦点

我确实知道为什么浏览器兼容性问题可能导致其专门无法在chrome中运行,或者如果可以的话如何解决此问题?

0 个答案:

没有答案