我當(dāng)時(shí)也是比較迷茫選哪個(gè)控件比較好,后面再github上找到一個(gè)這個(gè)SwipeMenuListView開源項(xiàng)目完成的,使用這個(gè)項(xiàng)目非常簡(jiǎn)單,里面有兩個(gè)例子,復(fù)雜的跟簡(jiǎn)單的,我當(dāng)時(shí)自己寫了個(gè)Demos來(lái)學(xué)習(xí),廢話不多說(shuō)了,直接貼代碼。
我們提供的服務(wù)有:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、平定ssl等。為數(shù)千家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的平定網(wǎng)站制作公司public class MainActivity extends Activity {
private AppAdapter mAdapter;
private SwipeMenuListView mListView;
ArrayList<String> data=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
for (int i = 0; i < 9; i++) {
data.add("position為"+i);
}
mListView = (SwipeMenuListView) findViewById(R.id.listView);
mAdapter = new AppAdapter();
mListView.setAdapter(mAdapter);
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "open" item
SwipeMenuItem openItem = new SwipeMenuItem(
getApplicationContext());
// set item background
openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9,
0xCE)));
// set item width
openItem.setWidth(dp2px(90));
// set item title
openItem.setTitle("Open");
// set item title fontsize
openItem.setTitleSize(18);
// set item title font color
openItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(openItem);
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(
getApplicationContext());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,
0x3F, 0x25)));
// set item width
deleteItem.setWidth(dp2px(90));
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};
mListView.setMenuCreator(creator);
mListView.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public void onMenuItemClick(int position, SwipeMenu menu, int index) {
//index=0 open index =1 刪除
switch (index) {
case 0:
Toast.makeText(MainActivity.this, ""+position, Toast.LENGTH_SHORT).show();
break;
case 1:
// Log.e("position", ""+position);
data.remove(position);
Log.e("onMenuItemClick 1", "position="+position+"##index="+index+"data.tos"+data.toString());
Toast.makeText(MainActivity.this, ""+position+"index="+index, Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
mAdapter.notifyDataSetChanged();
}
}, 500);
break;
default:
break;
}
}
});
}
class AppAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
Log.e("getview", data.toString());
return data.size();
}
@Override
public String getItem(int position) {
// TODO Auto-generated method stub
return data.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// biao bb = null;
// if(convertView==null){
// convertView = getLayoutInflater().inflate(R.layout.item, null);
// bb = new biao();
// bb.text = (TextView) convertView.findViewById(R.id.textView1);
// convertView.setTag(bb);
// }else{
// bb = (biao) convertView.getTag();
// }
// bb.text.setText(data.get(position));
// Log.e("tv", data.get(position));
if (convertView == null) {
convertView = View.inflate(getApplicationContext(),
R.layout.item, null);
new ViewHolder(convertView);
}
ViewHolder holder = (ViewHolder) convertView.getTag();
holder.tv.setText(data.get(position));
return convertView;
}
class ViewHolder {
TextView tv;
public ViewHolder(View view) {
tv = (TextView) view.findViewById(R.id.textView1);
view.setTag(this);
}
}
}
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
}
主XML也是很簡(jiǎn)單的。
:
<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"
tools:context=".MainActivity" >
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站題目:listview向左滑有刪除功能-創(chuàng)新互聯(lián)
當(dāng)前地址:http://jinyejixie.com/article8/disjop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、品牌網(wǎng)站制作、搜索引擎優(yōu)化、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、營(yíng)銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容