0

I am customized an adapter for listview and its word fine. But when i set onclicklistener to an view in custom adapter row view the onitemclicklistner not working.

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    try{
        if(convertView==null)
        {
            convertView=mInflater.inflate(R.layout.marker_row_view, null);
            holder=new ViewHolder();
            holder.Name=(TextView)convertView.findViewById(R.id.ProeprtyName);
            holder.image=(ImageView)convertView.findViewById(R.id.RightArrow);
            convertView.setTag(holder);
        }
        else
        {
            holder=(ViewHolder)convertView.getTag();
        }

      holder.Name.setText(propertyNames[position]);
      if(selectedPosition == position){
          Log.d("", "selected");
          convertView.setBackgroundColor(Color.BLUE);
          convertView.setBackgroundColor(Color.parseColor("#3B79FF"));
          holder.Name.setTextColor(Color.WHITE);
      }else{
          //convertView.setBackgroundResource(R.drawable.savsearch_bg_district);
          holder.Name.setTextColor(Color.BLACK);
      }
      holder.Name.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.d("fdsf", "on");
                Globalclass global = (Globalclass) ((Activity)context).getApplication();
                global.setMarkerTextClick(true);
            }
      });
      holder.image.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.d("fdsf", "on");
                Globalclass global = (Globalclass) ((Activity)context).getApplication();
                global.setMarkerTextClick(false);
            }
      });

    }catch (Exception e) {
        e.printStackTrace();
    }

    return convertView;
}

and the code for listview onitemclicklisner is

final MarkerInfoAdapter adapter = new MarkerInfoAdapter(PropertyMapList.this, names);
                                final ListView list = (ListView) CustomMarker.findViewById(R.id.listView1);
                                list.setAdapter(adapter);list.setOnItemClickListener(new OnItemClickListener() {

                                    @Override
                                    public void onItemClick(
                                            AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                                        Log.d("", "fsdfdsfds");
                                        ((MarkerInfoAdapter)adapter).setSelected(arg2);
                                    }
                                });
Sampath Kumar
  • 4,433
  • 2
  • 27
  • 42
  • try CustomMarker.list.setOnItemClickListener...... – Lucifer May 29 '13 at 08:18
  • http://stackoverflow.com/questions/15113969/onclicklistner-not-working-in-fragment-listview – jeevamuthu May 29 '13 at 08:19
  • Which are the views you trying to implement `onClicklistener()` ?? – Chintan Soni May 29 '13 at 08:20
  • I want to know which view is clicked (Text or Image), If text means i will call some function and Image means will call other one.. i can get the view click so i implemented this onclicklisner for each view now this working but cant get the onitemclickLisner for listview?? – Sampath Kumar May 29 '13 at 09:10

2 Answers2

1

you can try this:

convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
               setSelected(position); 
            }
      });
NaserShaikh
  • 1,576
  • 2
  • 23
  • 39
0

Since you are adding the same code in in onClick listener ,there no point of using on click listener on row views.Instead you can add the following code in onItemClick

 Globalclass global = (Globalclass) ((Activity)context).getApplication();
   global.setMarkerTextClick(false);

If you still want to implement on click on specific views ,make sure

  • views are not clickable

  • android:focusable="false"

  • android:focusableInTouchMode="false"

Add the following attributes in your listview tag

 android:clickable="true"
 android:descendantFocusability="beforeDescendants"

This link will solve your problem Android: Grid view with clickable grid items and nested views (buttons, checkboxes)

Community
  • 1
  • 1
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66
  • Onclick of **textview** i want that itemclicklistener to function and onclick of the **rightArrow(image)** i need to do some logical work for marker class... – Sampath Kumar May 29 '13 at 08:49