在我开发的Android应用程序上,我遇到了这种情况。
在片段中,有一个ListView,其中包含使用自定义ArrayAdapter(名为 ArrayAdapter_ClientiInput )的客户列表(存储在 Customer_InputOld 类的实例中)。单行包含一个带有两个TextView的ViewFlipper和七个几乎相同的TextView。
我在适配器中放了一个ClickListner和一个TouchListner,所以在应用程序创建的一行的点击(和触摸)上。这是有效的,除了这些事件不是在整行上触发的事实。
只有80%的粗略行是"可点击",而最后一个textView没有响应列表器。
真诚地我不知道要发布什么代码导致我不知道问题出在哪里:我试图在View of View本身上干掉View.getWidth(),但实际上宽度是1280 px,整个设备的宽度。
使用此 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>
虽然适配器代码是这样的:
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 :(得分:0)
OP解决方案。
在最后一个TextView中,我放了android:capitalize="words"
,这是一个EditText的属性,而不是Textview的属性!所以,当我点击最后一个“20%”的屏幕时 - 巧合的是,TextBox-tha应用程序认为点击是在TextView而不是行!