Question

before implement viewHolder._linearLayout.setOnClickListener in PrdDocListAdapter , the listview selected row color change event is work. But after create onclick listener , selected row color change event does not work. please clear for me.

this is a part of cashsaleolddoc.xml

<ListView android:id="@+id/lvlOldDoc" android:fadingEdge="none" 
              android:layout_width="fill_parent" android:layout_height="200.0dip" 
              android:cacheColorHint="@android:color/transparent"  
              android:listSelector="@drawable/listview_selector"
              android:drawSelectorOnTop="true"
              android:choiceMode="singleChoice"                  
              android:layout_weight="1.0" 
            />

this is listview_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

<!-- Selected --> 
  <item 
android:state_focused="true" 
android:state_pressed="false" 
android:drawable="@color/Lime_Green" /> <!--  @drawable/tab_focus -->

  <!-- Pressed -->
  <item 
   android:state_pressed="true" 
 android:drawable="@color/Lime_Green" /> <!--  @drawable/tab_press -->

</selector> 

this is PrdDocListAdapter

public class PrdDocListAdapter extends BaseAdapter {

private Context mContext;
private LayoutInflater inflater;
private List<CashSaleDocInfo> _CashSaleDocInfo;

public PrdDocListAdapter(Context paramContext,
        List<CashSaleDocInfo> paramList1) {
    this.mContext = paramContext;
    this._CashSaleDocInfo = paramList1;
}

@Override
public int getCount() {
    return _CashSaleDocInfo.size();
}

@Override
public Object getItem(int arg0) {
    return null;
}

@Override
public long getItemId(int arg0) {
    return 0;
}

@Override
public View getView(final int position, View convertView,
        ViewGroup parentView) {
    inflater = (LayoutInflater) mContext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

    final ViewHolder viewHolder;

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.cashsaleolddoclist, null);

        TextView txtOldDocNo = (TextView) convertView
                .findViewById(R.id.txtOldDocNo);
        TextView txtOldDocDate = (TextView) convertView
                .findViewById(R.id.txtOldDocDate);
        TextView txtOldDocCancelFlag = (TextView) convertView
                .findViewById(R.id.txtOldDocCancelFlag);
        TextView txtOldDocTable = (TextView) convertView
                .findViewById(R.id.txtOldDocTable);
        // EditText txtSelectDocNo = (EditText) convertView
        // .findViewById(R.id.txtSelectDocNo);

        viewHolder = new ViewHolder();
        viewHolder.txtDocNo = txtOldDocNo;
        viewHolder.txtDocDate = txtOldDocDate;
        viewHolder.txtCancelFlag = txtOldDocCancelFlag;
        viewHolder.txtTableNo = txtOldDocTable;
        // viewHolder.txtSelectDocNo = txtSelectDocNo;
        viewHolder._linearLayout = (LinearLayout) convertView
                .findViewById(R.id.linlayDocnoList);

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.txtDocNo.setText(this._CashSaleDocInfo.get(position)
            .getDOCUMENT_NO());
    viewHolder.txtDocDate.setText(dateFormat.format(this._CashSaleDocInfo
            .get(position).getDOCUMENT_DATE()));
    viewHolder.txtCancelFlag.setText(this._CashSaleDocInfo.get(position)
            .getCANCEL_FLAG());
    viewHolder.txtTableNo.setText(this._CashSaleDocInfo.get(position)
            .getSALEMAN_CODE());


    viewHolder._linearLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            String a = _CashSaleDocInfo.get(position).getDOCUMENT_NO()
                    .toString();
            MainActivity.setSelectDocNo(a);
        }
    });

    return convertView;
}

public static class ViewHolder {
    TextView txtDocNo;
    TextView txtDocDate;
    TextView txtCancelFlag;
    TextView txtTableNo;
    EditText txtSelectDocNo;
    LinearLayout _linearLayout;
}
}
Was it helpful?

Solution 2

my custom listview layout(cashsaleolddoclist.xml) is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:background="@drawable/listview_selector" android:clickable="true" android:id="@+id/linlayDocnoList" 
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout android:orientation="horizontal" android:background="@color/White" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TextView android:textSize="14.0dip" android:textColor="#ff000000" android:id="@+id/txtOldDocNo" android:padding="5.0dip"  android:layout_marginLeft="2.0dip" android:layout_width="160.0dip" android:layout_height="wrap_content" android:text="" android:gravity="center" android:textAlignment="gravity" />
    <TextView android:textSize="14.0dip" android:textColor="#ff000000" android:id="@+id/txtOldDocDate" android:padding="5.0dip" android:layout_width="140.0dip"  android:layout_marginLeft="3.0dip"  android:layout_height="wrap_content" android:text="" android:gravity="center" android:textAlignment="gravity"/>
    <TextView android:textSize="14.0dip" android:textColor="#ff000000" android:id="@+id/txtOldDocCancelFlag" android:padding="5.0dip" android:layout_width="70.0dip"  android:layout_marginLeft="3.0dip"  android:layout_height="wrap_content" android:text="" android:gravity="center" android:textAlignment="gravity"/>
    <TextView android:textSize="14.0dip" android:textColor="#ff000000" android:id="@+id/txtOldDocTable" android:padding="5.0dip" android:layout_width="fill_parent"  android:layout_height="wrap_content" android:text="" android:gravity="center" android:textAlignment="gravity"/>                
</LinearLayout>
<View android:background="#ff000000" android:layout_width="wrap_content" android:layout_height="1.0dip" />
</LinearLayout>

I have found solution my problem .Now I remove second linearlayout in cashsaleolddoclist.xml .And then listselector effect is still work. Thank for all of your answer

OTHER TIPS

Try this: In LinearLayout set android:clickable="true"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top