【发布时间】:2015-02-03 05:53:37
【问题描述】:
我有一个简单的listview,每行都有一个删除按钮
现在,当我单击删除按钮时,应删除选定的列表视图行。
这是我的列表视图:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView android:id="@+id/itemslistview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="75dp"/>
</RelativeLayout>
ListViewRow:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:padding="10dp"
android:textSize="16sp"
android:ems="10"
android:textColor="#800080" />
<ImageView
android:id="@+id/btndelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/delete"
android:layout_toRightOf="@+id/textView"
android:layout_marginTop="5dp"/>
</LinearLayout>
这就是我尝试删除的方式:
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
listrowposition= position;
Button del =(Button)findViewById(R.id.btndelete);
findViewById(R.id.deleteicon).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View arg0) {
MyList.remove(listrowposition);
adp.notifyDataSetChanged();
Toast.makeText(getApplicationContext(),
"Deleted ListItem Number " + listrowposition,
Toast.LENGTH_LONG).show();
}
});
Toast.makeText(getApplicationContext(),
"Click ListItem Number " + listrowposition,
Toast.LENGTH_LONG).show();
}
});
【问题讨论】:
标签: android listview selecteditem delete-row