-
Notifications
You must be signed in to change notification settings - Fork 2.7k
generateView int position is always 0 #14
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
Comments
Could you please paste your code? |
I did some more testing and i found out that if i pass a list that aready contains some items everything seem to work fine. The position is correct and the right item is deleted. public class MyAdapter extends SwipeAdapter
{
private Context context;
//holding the reference, i have an add button on the main activity that adds more strings in the list
private List<String> mylist;
public MyAdapter(Context context, List<String> mylist)
{
this.context = context;
this.mylist = mylist;
}
@Override
public View generateView(final int position, ViewGroup viewGroup)
{
View v = LayoutInflater.from(context).inflate(R.layout.list_layout, null);
final SwipeLayout swipeLayout = (SwipeLayout)v.findViewById(getSwipeLayoutResourceId(position));
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
swipeLayout.findViewById(R.id.myimageview).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
//The position here is always 0 for the new items
Toast.makeText(context, "my position : " + String.valueOf(position), Toast.LENGTH_SHORT).show();
//mylist.remove(position);
//notifyDataSetChanged();
}
});
return v;
}
@Override
public void fillValues(int position, View view)
{
TextView textView = (TextView) view.findViewById(R.id.mytextview);
textView.setText(mylist.get(position));
}
@Override
public int getCount()
{
return mylist.size();
}
@Override
public Object getItem(int position)
{
return mylist.get(position);
}
@Override
public long getItemId(int position)
{
return position;
} |
Hey guy. You should view the source of the remember: So, a quick way to solve this problem: move the following code: swipeLayout.findViewById(R.id.myimageview).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
//The position here is always 0 for the new items
Toast.makeText(context, "my position : " + String.valueOf(position), Toast.LENGTH_SHORT).show();
//mylist.remove(position);
//notifyDataSetChanged();
}
}); to @Override
public void fillValues(int position, View view)
{
TextView textView = (TextView) view.findViewById(R.id.mytextview);
textView.setText(mylist.get(position));
} |
Have a try, if any problem, feel free to contact me. |
Yes, |
It works right? I think I should add this notice in Wiki. It's also my mistake. :-D |
Yes i just tested it. Well i fall for it because of the View in both generateView and the usual getView |
ask a favor: The problem you met is really a pitfall (my mistake)... My English is not very well, I'm not good at writing, explaining. If you are available, could you please help this project to improve the wiki to prevent other developers get into this trouble again: |
Yes i can do some editing if you want :) But to let you know English is not my native language too! |
Do your best ! |
Click and swipe have some comflict.I want to enter another Activity when I click an item, but also I want to swipe left to show the BottomView and handle the BottomView.My code has something wrong?
My layout code: <com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
</com.daimajia.swipe.SwipeLayout> |
Try this: instead of |
@de-Stan I have tried:LinearLayout linoutMemo = (LinearLayout) convertview.findViewById(R.id.linoutMemo);But result is: the item can click to enter a new Activity,but this item can not swipe again. |
Ok, what i believe you should do is set an ItemClickListener on the listview from your activity/fragment: listView.setOnItemClickListener ... ; and start the activity from there. |
@de-Stan OK,what you answer is handle the problem.But if you set an ItemClickListener on the listview from your Activity,the click effect is always.No matter the SwipeLayout is open, the item can click always.But I what I want is: when the SwipeLayout is open, the SurfaceView in this item can not clicked, but the BottomView in the item can click because I want do something in the BottomView. |
You can use the SwipeLayout's status. From the ItemClickListener you will get a view which is a SwipeLayout. Do something like this: @Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
if((((SwipeLayout) view).getOpenStatus() == SwipeLayout.Status.Close))
{
//Start your activity
} |
@de-Stan My problem is solved, thank you very much! |
Glad i could help! |
@de-Stan Please help me in this. |
Sorry i can't understand what you asking. Some code could be helpful to see what you are up to. |
@de-Stan That is the the issue. Even i am not getting any method as explained in above comment. |
I haven't used the librady almost a year now, but i didn't have any problems as you describe. Maybe some things change or broke with an update? Or are you doing something wrong in your side? |
I have just check your repo and it have same issue and also implement that in my project which also have same issue. Please just get fresh copy of your repo and try it. |
Why the position is always 0 when generateView is called?
I want to make a listview and i hold a reference to a list with all the objects in the swipeadapter.
I have a trash imageview in the bottom view (just like in the tutorial) which when clicked it deletes that item, but i can't notify the adapter with the position since it's always 0. So the wrong item gets deleted.
The text was updated successfully, but these errors were encountered: