如何删除列表视图android的列表视图项? [英] How to remove list view item in list view android?
问题描述
在我的应用我有一个自定义列表视图。每当我点击关闭图像列表项,列表项布局必须与空间被删除。我用的知名度:走了属性,删除列表项目布局,但空间是可见的。我正在使用滚动视图列表视图,,这也没有工作....请帮助我。
@覆盖
公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
// TODO自动生成方法存根
如果(吹气== NULL)
吹气=(LayoutInflater)活动
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
如果(convertView == NULL)
convertView = inflater.inflate(R.layout.recharge_listitem,NULL);
TextView的ACCOUNTNUMBER =(TextView中)convertView
.findViewById(R.id.accountnumber);
TextView的服务名=(的TextView)convertView
.findViewById(R.id.servicetypname);
TextView的planamount =(TextView中)convertView
.findViewById(R.id.rechargeamount);
最后ImageView的密切=(ImageView的)convertView
.findViewById(R.id.crosse_close_img);
最终的LinearLayout layoutrecharge =(的LinearLayout)convertView.findViewById(R.id.rechargelay);
close.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
layoutrecharge.setVisibility(View.GONE);
}
});
accountnumber.setText(RS。+ bpData.get(位置).getAccountNumber());
servicename.setText(bpData.get(位置).getServicename());
planamount.setText(bpData.get(位置).getRechargeamount()); 返回convertView;
}}
XML:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@绘制/背景>
<滚动型
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_marginLeft =2DP
机器人:layout_marginRight =2DP 机器人:fillViewport =真正的> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:背景=#1e365a> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =25dp
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:layout_margin =10dp
机器人:文字=PAYMENT
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =20dp/>
< / RelativeLayout的>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =25dp
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:layout_marginTop =10dp
机器人:文字=你的充电
机器人:文字颜色=#1e365a
机器人:TEXTSIZE =20dp/>
< / RelativeLayout的> <查看
机器人:layout_width =FILL_PARENT
机器人:layout_height =4DP
机器人:背景=@绘制/ dottedline_view/>
< ListView控件 机器人:ID =@ + ID / recharge_lv
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:知名度=水涨船高> < /&的ListView GT; <查看
机器人:layout_width =FILL_PARENT
机器人:layout_height =0.8dp 机器人:layout_marginTop =12dp
机器人:背景=#1e365a/> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:weightSum =2> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =25dp
机器人:layout_weight =1
机器人:layout_margin =10dp
机器人:文字=支付金额
机器人:文字颜色=#1e365a
机器人:TEXTSIZE =20dp/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =25dp
机器人:layout_weight =1
机器人:layout_margin =10dp
机器人:文字=Rs.130
机器人:文字颜色=#1e365a
机器人:TEXTSIZE =20dp/>
< / LinearLayout中>
<的LinearLayout
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginBottom =8DP
机器人:layout_marginLeft =20dp
机器人:layout_marginRight =8DP
机器人:layout_marginTop =8DP
机器人:重力=center_vertical
机器人:方向=横向
机器人:weightSum =100> <的EditText
机器人:ID =@ + ID / ev_b_dob
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =40dp
机器人:layout_weight =50
机器人:提示=输入coupn code
安卓的inputType =TEXT> < requestFocus的/>
< /&的EditText GT; <按钮
机器人:ID =@ + ID / bt_apply
风格=@风格/ payment_button_style
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =40dp
机器人:layout_marginLeft = - 5DP
机器人:layout_weight =20
机器人:比重=中心
机器人:文字=应用/>
< / LinearLayout中> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:layout_marginTop =10dp
机器人:layout_marginLeft =28dp
机器人:layout_marginRight =30dp> <复选框
机器人:ID =@ + ID / cb_reload_cash
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
<的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字=用支付现金刷新
机器人:文字颜色=#1e365a
机器人:TEXTSIZE =20dp
机器人:layout_marginLeft =12dp/> < / LinearLayout中>
<按钮
机器人:ID =@ + ID / atmdebit_btn
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =28dp
机器人:layout_marginRight =30dp
机器人:layout_marginTop =20dp
机器人:背景=#F93249
机器人:比重=中心
机器人:paddingBottom会=8DP
机器人:paddingTop =8DP
机器人:文字=ATM /借记/贷记
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =20dp/>
<按钮
机器人:ID =@ + ID / netbankng_btn
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =28dp
机器人:layout_marginRight =30dp
机器人:layout_marginTop =20dp
机器人:背景=#F93249
机器人:比重=中心
机器人:paddingBottom会=8DP
机器人:paddingTop =8DP
机器人:文字=网上银行
机器人:文字颜色=#FFFFFF
机器人:TEXTSIZE =20dp/>< / LinearLayout中>
< /滚动型>
< / LinearLayout中>
请帮我。
自定义列表视图项:
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=横向
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:ID =@ + ID / rechargelay> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=横向
机器人:weightSum =3> <的LinearLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_weight =1>
<的TextView
机器人:ID =@ + ID / ACCOUNTNUMBER
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=8008505106/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5DP
机器人:文本=(/> <的TextView
机器人:ID =@ + ID / servicetypname
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=沃达丰/> <的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=)/>
< / LinearLayout中> <的TextView
机器人:ID =@ + ID / rechargeamount
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=RS.30
机器人:layout_weight =1/> < ImageView的
机器人:ID =@ + ID / crosse_close_img
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@绘制/关闭
机器人:layout_weight =1/>
< / LinearLayout中>
< / LinearLayout中>
设置 View.GONE
的视图不从ListView中删除行正道。删除行从适配器的数据源中删除选择行项目,并调用notify适配器的数据改变方法来填充变化:
close.setTag(位置);
close.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
INT deletePos =的Integer.parseInt(v.getTag()的toString());
bpData.remove(deletePos);
notifyDataSetChanged();
}
});
In my application i have one custom list view. whenever i click the close image list item, the list item layout must be removed with space. i used visibility:gone attribute, the list item layout deleted but the space is visible. I am using listview in scroll view ,,that was also not working....please help me out.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.recharge_listitem, null);
TextView accountnumber = (TextView) convertView
.findViewById(R.id.accountnumber);
TextView servicename = (TextView) convertView
.findViewById(R.id.servicetypname);
TextView planamount = (TextView) convertView
.findViewById(R.id.rechargeamount);
final ImageView close = (ImageView) convertView
.findViewById(R.id.crosse_close_img);
final LinearLayout layoutrecharge=(LinearLayout)convertView.findViewById(R.id.rechargelay);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layoutrecharge.setVisibility(View.GONE);
}
});
accountnumber.setText("Rs."+bpData.get(position).getAccountNumber());
servicename.setText(bpData.get(position).getServicename());
planamount.setText(bpData.get(position).getRechargeamount());
return convertView;
}
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e365a">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:text="PAYMENT"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:text="Your Recharges"
android:textColor="#1e365a"
android:textSize="20dp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="4dp"
android:background="@drawable/dottedline_view" />
<ListView
android:id="@+id/recharge_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</ListView>
<View
android:layout_width="fill_parent"
android:layout_height="0.8dp"
android:layout_marginTop="12dp"
android:background="#1e365a" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Amount to be Paid"
android:textColor="#1e365a"
android:textSize="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_weight="1"
android:layout_margin="10dp"
android:text="Rs.130"
android:textColor="#1e365a"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="100" >
<EditText
android:id="@+id/ev_b_dob"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="50"
android:hint="Enter coupn code"
android:inputType="text" >
<requestFocus />
</EditText>
<Button
android:id="@+id/bt_apply"
style="@style/payment_button_style"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginLeft="-5dp"
android:layout_weight="20"
android:gravity="center"
android:text="Apply" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp">
<CheckBox
android:id="@+id/cb_reload_cash"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay using Reload Cash"
android:textColor="#1e365a"
android:textSize="20dp"
android:layout_marginLeft="12dp"/>
</LinearLayout>
<Button
android:id="@+id/atmdebit_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="ATM/DEBIT/CREDIT"
android:textColor="#ffffff"
android:textSize="20dp"/>
<Button
android:id="@+id/netbankng_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="30dp"
android:layout_marginTop="20dp"
android:background="#F93249"
android:gravity="center"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="NET BANKING"
android:textColor="#ffffff"
android:textSize="20dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
please help me.
custom listview item:
<?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"
android:id="@+id/rechargelay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/accountnumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8008505106" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="(" />
<TextView
android:id="@+id/servicetypname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vodafone" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=")" />
</LinearLayout>
<TextView
android:id="@+id/rechargeamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RS.30"
android:layout_weight="1" />
<ImageView
android:id="@+id/crosse_close_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/close"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Set View.GONE
for View is not right way to remove row from ListView. to remove row remove select row item from Adapter data-source and call notify data change method of adapter to populate changes:
close.setTag(position);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int deletePos=Integer.parseInt(v.getTag().toString());
bpData.remove(deletePos);
notifyDataSetChanged();
}
});
这篇关于如何删除列表视图android的列表视图项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!