我希望在名单上打一个支票箱或洞,子,并放下浮标语,但只为零位工作。
String[] NewTransferItems = { "Spendability", "Accounts", "Budgets",
"I m keeping" };
以及
dashboardEditListView = (ListView) findViewById(R.id.dashboardEditListView);
listAdapter = new DashboardEditListAdapater();
dashboardEditListView.setAdapter(listAdapter);
dashboardEditListView.s
etOnItemClickListener(listClickListner);
我的改编者:
class DashboardEditListAdapater extends ArrayAdapter<String> implements OnClickListener{
DashboardEditListAdapater() {
super(DashboardEdit.this, R.layout.generic_list_row,
NewTransferItems);
}
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println("Called Method " + getItem(position)
+ " Position " + position);
View row = null;
EditText editText = null;
CheckBox checkBox = null;
if (position == 0 || position == 1 || position == 2) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.generic_list_row_withtoggle,
parent, false);
checkBox = (CheckBox) findViewById(R.id.checkBox);
// init
} else if (position == 3) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.generic_list_row_with_edittext,
parent, false);
editText = (EditText) findViewById(R.id.rowRightEditText);
if(editText != null) {
editText.setVisibility(View.VISIBLE);
}
}
LinearLayout rowWrapper = (LinearLayout) row
.findViewById(R.id.rowWrapper);
LinearLayout rowHeadWrapper = (LinearLayout) row
.findViewById(R.id.rowHeadWrapper);
rowHeadWrapper.setVisibility(ViewGroup.GONE);
String item = getItem(position);
if (position == 0) {
if(checkBox != null){
checkBox.setTag(position);
checkBox.setOnClickListener(this);
}
} else if (position == 1) {
if(checkBox != null){
checkBox.setTag(position);
checkBox.setOnClickListener(this);
}
} else if (position == 2) {
if(checkBox != null){
checkBox.setTag(position);
checkBox.setOnClickListener(this);
}
}
TextView rowTitle = (TextView) row.findViewById(R.id.rowTitle);
rowTitle.setText(item);
return row;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Clicked");
}
}
这里是我的XML,用于通用_list_row_withtoggle
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.mytalk.androidapp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/rowWrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dip"
android:layout_marginRight="8dip"
android:background="#FFF"
android:orientation="vertical"
android:padding="0dip" >
<LinearLayout
android:id="@+id/rowHeadWrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/cell_header_bg"
android:orientation="vertical"
android:paddingLeft="8dip" >
<TextView
android:id="@+id/rowHead"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:text="Profile"
android:textColor="#000"
android:textSize="18dip"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingLeft="8dip" >
<!--
<ImageView
android:id="@+id/rowImage"
android:layout_width="60dp"
android:layout_height="36dp"
android:layout_centerVertical="true"
android:src="@drawable/bahrain_flag"
android:visibility="gone" />
-->
<TextView
android:id="@+id/rowTitle"
android:layout_width="200dip"
android:layout_height="45dip"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dip"
android:layout_toRightOf="@id/rowImage"
android:gravity="center_vertical"
android:text="Current"
android:textColor="#000"
android:textSize="15dip"
android:textStyle="bold" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dip"
android:layout_marginRight="10dip"
/>
<!--
<ToggleButton
android:id="@+id/togglebutton2"
android:layout_width="60dip"
android:layout_height="40dip"
android:layout_alignParentRight="false"
android:layout_marginLeft="20dip"
android:layout_marginRight="10dip"
android:textOff="OFF"
android:textOn="ON"
android:visibility="visible" />
-->
</RelativeLayout>
</LinearLayout>
</LinearLayout>
I used ToggleButton 以及CheckBox both, but there is not difference, it works only for zero position, otherwise not calling onClickListner.
I am unable to underst以及the reason, why its happening.
让我知道,什么还不清楚。