如何在android gridview中获取当前焦点项的索引。 <EOM> </EOM>

时间:2012-07-09 09:02:32

标签: android gridview grid focus

是否有任何API可以跟踪Android中GridView的索引?

1 个答案:

答案 0 :(得分:6)

您是否为GridView设置了OnItemClickListener

gridView.setOnItemClickListener(
    new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(
                getApplicationContext(), 
                String.format("Clicked on position #%s (id = %s)", position, id), 
                Toast.LENGTH_SHORT
            ).show();
        }   
    }
);