gridview setonitemclicklistener仅从第一个项目获取值

时间:2013-12-06 15:40:54

标签: android gridview

我在textview(passID_l)中有一个包含值的gridview。 gridview中的每个项目都有不同的值。单击某个项目时,该项目的值将传递给另一个片段。

问题是,无论您单击哪个项目,将传递给捆绑包的值始终来自第1个项目。 例如第1项的值为“1”......第3项的值为“3”。当我点击第3项时,将传递“1”而不是“3”

gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {
            TextView text = (TextView) gridView.findViewById(R.id.passId_l);
            String tEXT = text.getText().toString();
            Toast.makeText(getActivity().getBaseContext(), tEXT, Toast.LENGTH_LONG).show();
            videoList firstFrag = new videoList(); 
            Bundle bundle = new Bundle();
            bundle.putString("key", tEXT);
            firstFrag.setArguments(bundle);
            android.app.FragmentTransaction ft = getFragmentManager().beginTransaction().replace(R.id.content_frame, firstFrag);
            ft.addToBackStack(null);
            ft.commit(); 
        }
    });

1 个答案:

答案 0 :(得分:0)

使用

        TextView text = (TextView) v.findViewById(R.id.passId_l);

而不是

        TextView text = (TextView) gridView.findViewById(R.id.passId_l);

从GridView的选定项目中获取TextView