Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #80

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.baoyz.swipemenulistview.demo;

import java.util.ArrayList;
import java.util.List;

import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.baoyz.swipemenulistview.SwipeMenuListView;
import com.baoyz.swipemenulistview.SwipeMenuListView.OnMenuItemClickListener;
import com.example.swipelistview.R;
import com.example.swipelistview.R.id;
import com.example.swipelistview.R.layout;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class DynamicActivity extends Activity {
public SwipeMenuListView listview;
List<User> values = new ArrayList<User>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
listview = (SwipeMenuListView) this.findViewById(R.id.listView);
for (int i = 0; i < 6; i++) {
User user=new User();
user.setName("1");
values.add(user);
}
for (int j = 0; j < 3; j++) {
User user=new User();
user.setName("2");
values.add(user);
}
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(90);
// set item title
openItem.setTitle("收藏");
// 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(90);
// add to menu
menu.addMenuItem(deleteItem);
}
};
listview.setMenuCreator(creator);
final MyAdapter adapter = new MyAdapter(this, values);
listview.setAdapter(adapter);
listview.setOnMenuItemClickListener(new OnMenuItemClickListener(){

@Override
public boolean onMenuItemClick(int position, SwipeMenu menu,
int index) {
// TODO Auto-generated method stub
String name= ((User)adapter.getItem(position)).getName();
if(name.equals("1")){
((User)adapter.getItem(position)).setName("2");
}
if(name.equals("2")){
((User)adapter.getItem(position)).setName("1");
}
adapter.notifyDataSetChanged();
return false;
}

});

}
}
81 changes: 81 additions & 0 deletions demo/src/main/java/com/baoyz/swipemenulistview/demo/MyAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.baoyz.swipemenulistview.demo;

import java.util.List;

import com.baoyz.swipemenulistview.BaseSwipListAdapter;
import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.example.swipelistview.R;
import com.example.swipelistview.R.id;
import com.example.swipelistview.R.layout;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseSwipListAdapter {
public List<User> list = null;
public Context context;

public MyAdapter(Context cxt, List<User> values) {
this.context = cxt;
list = values;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.item,
null);
holder=new ViewHolder();
holder.tx = (TextView) convertView.findViewById(R.id.tip);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tx.setText(list.get(position).getName());
return convertView;
}

@Override
public void SwipeMenuUpdate(SwipeMenu menu, int position) {
// TODO Auto-generated method stub
if(list.get(position).getName().equals("2")){
SwipeMenuItem item=menu.getMenuItem(0);
item.setTitle("已收藏");
menu.updateMenuItem(item, 0);
}else if(list.get(position).getName().equals("1")){
SwipeMenuItem item=menu.getMenuItem(0);
item.setTitle("收藏");
menu.updateMenuItem(item, 0);
}
}

public class ViewHolder {
TextView tx;
}
}
14 changes: 14 additions & 0 deletions demo/src/main/res/layout/item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tip"
android:layout_width="fill_parent"
android:layout_height="100dip"
android:text="test"
/>


</LinearLayout>
12 changes: 12 additions & 0 deletions demo/src/main/res/layout/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<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="${packageName}.${activityClass}" >

<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015 nimengbo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
* The MIT License (MIT)
*
* Copyright (c) 2015 nimengbo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.baoyz.swipemenulistview;

import android.widget.BaseAdapter;

/**
* Created by Abner on 15/11/20.
* QQ 230877476
* Email [email protected]
* github https://github.com/nimengbo
* Created by Abner on 15/11/20. QQ 230877476 Email [email protected] github
* https://github.com/nimengbo
*/
public abstract class BaseSwipListAdapter extends BaseAdapter {

public boolean getSwipEnableByPosition(int position){
return true;
}
public boolean getSwipEnableByPosition(int position) {
return true;
}

public void SwipeMenuUpdate(SwipeMenu menu, int position) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class SwipeMenu {
private Context mContext;
private List<SwipeMenuItem> mItems;
private int mViewType;
private SwipeMenuView mSwipeMenuView;

public SwipeMenu(Context context) {
mContext = context;
Expand All @@ -42,6 +43,10 @@ public SwipeMenuItem getMenuItem(int index) {
return mItems.get(index);
}

public void updateMenuItem(SwipeMenuItem item, int viewId) {
mSwipeMenuView.updateItem(mItems.get(item.getId()), viewId);
}

public int getViewType() {
return mViewType;
}
Expand All @@ -50,4 +55,8 @@ public void setViewType(int viewType) {
this.mViewType = viewType;
}

public void setSwipeMenuView(SwipeMenuView swipeMenuView) {
mSwipeMenuView = swipeMenuView;
}

}
Loading