获取自定义适配器android的视图

时间:2013-10-15 06:17:10

标签: java android onclicklistener onitemclicklistener

如何获取自定义适配器的视图?我知道我可以使用onclicklistener获取视图,但我不想使用它也会给我一个null的错误。我有这个代码来获取listView项目的视图,但事情是我不会让我动画它

代码:

result_list.setOnTouchListener( new OnTouchListener() {
                private float startX;
                private float startY;
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        startX = event.getX();
                        startY = event.getY();
                        break;
                    case MotionEvent.ACTION_UP: {
                        float endX = event.getX();
                        float endY = event.getY();
                        if (isAClick(startX, endX, startY, endY)) { 
                            Log.d("click", "clicked");   
                            //result_list.setItemChecked(position, true);
                            itemPositionView = customAdapter.getView(position, null, result_list);
                            itemPositionView.animate().setDuration(300).translationX(widthListView).alpha(0).
                            withEndAction(new Runnable() {
                                @Override
                                public void run() {
                                    //setResult(Activity.RESULT_OK,new Intent().putExtra("bussStopCode", data.get(i).getStopCode()).putExtra("bussStopName", data.get(i).getStopName()));
                                    ////int get 1
                                    //data.remove(i);
                                    listLastPostion = position;
                                    //customAdapter.notifyDataSetChanged();
                                    //view.setTranslationX(0);

                                    //Log.d("data",conreq.getCollectedData().getBusRouteSetData().get(temporaryInteger - 1).getRouteHeading());
                                    Bundle bundle = new Bundle();
                                    bundle.putString("busdestination", conreq.getCollectedData().getBusRouteSetData().get(position).getRouteHeading());
                                    bundle.putString("busnumber", conreq.getCollectedData().getBusRouteSetData().get(position).getRouteNo());
                                    Fragment fragment = new FragmentNextTripForStop();
                                    fragment.setArguments(bundle);
                                    FragmentTransaction fragmentManager = getFragmentManager().beginTransaction();
                                    fragmentManager.setCustomAnimations(R.anim.right_left_anim_x_left,R.anim.right_left_anim_x_right,R.anim.left_right_anim_x_left,R.anim.left_right_anim_x_right);
                                    fragmentManager.add(R.id.fragment_searched_data_xml, fragment).addToBackStack(null).commit();
                                   // finish();
                                    //overridePendingTransition(R.anim.right_left_anim_x_left,R.anim.right_left_anim_x_right);

                                }
                            }); 
                        }
                        break;
                    }
                    }
                    return false;
                }
            });

位置是我从onclicklister中获取的位置当我从onclickListerner获取视图时它会给我一个null的错误

result_list.setOnItemClickListener(new OnItemClickListener(){

            @Override
            public void onItemClick(AdapterView<?> av, final View view,
                     final int i, long i2) {
                //result_list.setEnabled(false);
                getViewPosition(i);

            }});

我也参加了决赛,但仍然在视线而不是位置上给我一个错误

    10-15 02:22:44.411: E/InputEventReceiver(13793): Exception dispatching input event.
10-15 02:22:44.411: E/MessageQueue-JNI(13793): Exception in MessageQueue callback: handleReceiveCallback
10-15 02:22:44.421: E/MessageQueue-JNI(13793): java.lang.NullPointerException
10-15 02:22:44.421: E/MessageQueue-JNI(13793):  at com.example.octranspodestination1.MainActivity$FragmentMainClass$4.onTouch(MainActivity.java:384)
10-15 02:22:44.421: E/MessageQueue-JNI(13793):  at android.view.View.dispatchTouchEvent(View.java:7241)
10-15 02:22:44.421: E/MessageQueue-JNI(13793):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
10-15 02:22:44.421: E/MessageQueue-JNI(13793):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1914)
10-15 02:22:44.421: E/MessageQueue-JNI(13793):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2185)

第384行是这样的:

itemPositionView.animate().setDuration(300).translationX(widthListView).alpha(0).

0 个答案:

没有答案