Android : OnClickListnernot called on the whole View

on Thursday, September 4, 2014


On an Android application I am developping i got this situation.


In a Fragment there is a ListView that contains a list of customers (stored in instances of the Customer_InputOld class) using a customized ArrayAdapter (named ArrayAdapter_ClientiInput). The single row contains a ViewFlipper with two TextViews and seven nearly identical TextViews.


I put a ClickListner and a TouchListner in the Adapter, so on the click (and the touch) of a line the application make something. This works, except for the fact that these events are not triggered on the whole row.


Only the rough 80% of the row is "clickable", while the last textView does not respond to the listner.


Sincerely I don't know what code to post cause I have no idea where the problem could be: I tried to toast the View.getWidth() on the Click of the View itself, but actually the width is 1280 px, the entire device's width.


The single row is inflated with this customer_row.xml



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
tools:context=".MyActivity">

<ViewFlipper
android:id="@+id/capitalViewFlipper"
android:layout_width="75dp"
android:layout_height="75dp">

<TextView
android:id="@+id/customerLogo"

android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ABCDEF"
android:gravity="center"
android:text="D"


android:textColor="#fff"
android:textSize="28pt" />

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FBBB"
android:gravity="center"
android:src="@drawable/ic_selected_done" />


</ViewFlipper>

<TextView
android:id="@+id/ragioneSocialeViewList"
android:layout_width="400dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/capitalViewFlipper"
android:layout_gravity="center"
android:layout_toRightOf="@+id/capitalViewFlipper"
android:gravity="center_vertical"
android:padding="10dip"

android:singleLine="true"

android:text="Dummy Customer"
android:textColor="#000"
android:textSize="24dp" />

<TextView
android:id="@+id/canaleViewList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/capitalViewFlipper"
android:layout_alignLeft="@id/ragioneSocialeViewList"
android:layout_gravity="center"
android:layout_marginBottom="-7dp"


android:gravity="center"
android:padding="10dip"
android:text="Dummy type"
android:textColor="#000"
android:textSize="20dp" />

<TextView
android:id="@+id/sollecitiViewList"
android:layout_width="125dp"
android:layout_height="75dp"

android:layout_alignBottom="@+id/capitalViewFlipper"
android:layout_alignTop="@+id/capitalViewFlipper"
android:layout_gravity="center"
android:layout_toRightOf="@+id/ragioneSocialeViewList"
android:gravity="center"


android:padding="10dip"
android:text="2"
android:textColor="#000"
android:textSize="22dp" />

<TextView
android:id="@+id/tipoViewList"
android:layout_width="125dp"
android:layout_height="75dp"

android:layout_alignBottom="@+id/capitalViewFlipper"
android:layout_alignTop="@+id/capitalViewFlipper"

android:layout_toRightOf="@+id/sollecitiViewList"

android:gravity="center"

android:padding="10dip"
android:text="F/S"
android:textColor="#000"
android:textSize="22dp" />

<TextView
android:id="@+id/emailViewList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/telefonoViewList"
android:layout_alignRight="@+id/telefonoViewList"
android:layout_alignTop="@+id/capitalViewFlipper"
android:gravity="center"

android:padding="10dip"
android:text="dummymail@gmail.com"
android:textAlignment="center"
android:textColor="#000"

android:textSize="22dp" />

<TextView
android:id="@+id/telefonoViewList"
android:layout_width="350dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/capitalViewFlipper"
android:layout_gravity="center"
android:layout_marginBottom="-7dp"
android:layout_toRightOf="@+id/tipoViewList"

android:gravity="center"
android:padding="10dip"
android:text="tel. 035424344"
android:textColor="#000"
android:textSize="22dp" />

<TextView
android:id="@+id/ultimoOrdineViewList"
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_alignBottom="@+id/capitalViewFlipper"
android:layout_alignTop="@+id/capitalViewFlipper"
android:layout_gravity="center"
android:layout_toRightOf="@+id/emailViewList"
android:capitalize="words"
android:gravity="center_vertical|right"
android:padding="10dip"
android:singleLine="true"
android:text="21/12/2012"
android:textColor="#000"
android:textSize="22dp" />

</RelativeLayout>


While the Adapter Code is this:



public class ArrayAdapter_ClientiInput extends ArrayAdapter<CustomerInputOld> {

public EventLog.Event ImageTouched;
//public ListView customerListView;
private ArrayList<CustomerInputOld> list;
private Context context;

//this custom adapter receives an ArrayList of RowData objects.
//RowData is my class that represents the data for a single row and could be anything.
public ArrayAdapter_ClientiInput(Context context, int textViewResourceId, ArrayList<CustomerInputOld> rowDataList) {
//populate the local list with data.
super(context, textViewResourceId, rowDataList);
this.list = new ArrayList<CustomerInputOld>();
this.list.addAll(rowDataList);
this.context = context;
}

public View getView(final int position, View convertView, ViewGroup parent) {
//creating the ViewHolder we defined earlier.
ViewHolder_CustomerRow holder = new ViewHolder_CustomerRow();

//creating LayoutInflater for inflating the row layout.
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

//inflating the row layout we defined earlier.
convertView = inflater.inflate(R.layout.customers_row, null);

//setting the views into the ViewHolder.
holder.title = (TextView) convertView.findViewById(R.id.ragioneSocialeViewList);
holder.capital = (TextView) convertView.findViewById(R.id.customerLogo);
holder.flipper = (ViewFlipper) convertView.findViewById(R.id.capitalViewFlipper);
//holder.line = (RelativeLayout) convertView.findViewById(R.id.customer_whole_row);

holder.canale = (TextView) convertView.findViewById(R.id.canaleViewList);
holder.solleciti = (TextView) convertView.findViewById(R.id.sollecitiViewList);
holder.email = (TextView) convertView.findViewById(R.id.emailViewList);
holder.tipo = (TextView) convertView.findViewById(R.id.tipoViewList);
holder.numero = (TextView) convertView.findViewById(R.id.telefonoViewList);
holder.ultimoOrdine = (TextView) convertView.findViewById(R.id.ultimoOrdineViewList);

//define an onClickListener for the CheckBox.
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(getContext(),Integer.toString(v.getWidth()),Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getContext(), CustomerDetail.class);
intent.putExtra("name", list.get(position).getCompany());
getContext().startActivity(intent);
}
});

convertView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == android.view.MotionEvent.ACTION_DOWN) {
v.setBackgroundColor(0xFAAA);
} else if ( e.getAction() == android.view.MotionEvent.ACTION_UP ||
e.getAction() == android.view.MotionEvent.ACTION_CANCEL) {
isSelected(position, v);
}

//Ritorno false per permettere anche al OnClickListener di agire..
return false;
}
});


holder.flipper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CustomerListFragment.onRowIconClicked(position, (RelativeLayout) v.getParent(), (ViewFlipper) v, context);
}
});


//setting data into the the ViewHolder.
holder.title.setText(list.get(position).getCompany());

holder.capital.setText(list.get(position).getCompany().substring(0, 1).toUpperCase());
holder.capital.setBackgroundColor(list.get(position).getIconColor());

holder.canale.setText(list.get(position).getChannel());
holder.solleciti.setText(list.get(position).getReminders());
if (Integer.parseInt(list.get(position).getReminders()) >= 3)
holder.solleciti.setTextColor(0xffff0000);
holder.email.setText(list.get(position).getEmail());

holder.numero.setText("tel. " + list.get(position).number);
holder.ultimoOrdine.setText(new SimpleDateFormat("c d MMM ''yy").format(list.get(position).getLastOrderDate()));

if (list.get(position).getInvoiceCustomer() == null) {
if (list.get(position).getDeliveryCustomer() == null) {
holder.tipo.setText("F/S");
} else {
holder.tipo.setText("F");
}
} else {
holder.tipo.setText("S");
}

//modifiche nel caso in cui sia selezionato
if ( isSelected(position,convertView) ) {
holder.flipper.showNext();
}

//return the row view.
return convertView;

}

private boolean isSelected(int position, View v){
if (position == CustomerListFragment.customerSelected) {
v.setBackgroundColor(0xFFE6C86F);
return true;
} else {
v.setBackgroundColor(0xFFFFFFFF);
return false;
}
}


}

0 comments:

Post a Comment