简体   繁体   English

Listview onItemClickListener问题Adapter与Adapter一起使用

[英]Listview onItemClickListener issue Adapter with in Adapter

I am implementing FlipBoard kind of view where FlipAdapter has multiple pages which has getView() in this I am adding another listview with adapter and placing onitemclickListener as shown in below code . 我正在实现FlipBoard类型的视图,其中FlipAdapter具有多个在其中具有getView()的页面,我正在添加带有适配器的另一个listview并放置onitemclickListener,如下面的代码所示。 My problem is click listener is working on the page item which is second page while the view shown is 1st page 我的问题是点击侦听器正在处理第二页的页面项,而显示的视图是第一页

for eg: item1 , item 2 , item 3 are in page 1 and item 4 item 5 item 6 are in page 2 . 例如:项目1,项目2,项目3在页面1中,项目4项目5,项目6在页面2中。 When you click on item 1 , actually item 4 is clicked which is in 2nd page . 当您单击项目1时,实际上是在第二页中单击了项目4。

Could not find why any help will be appreciated. 找不到任何帮助的理由。

@Override public View getView(int position, View convertView, ViewGroup parent) { @Override public View getView(int position,View convertView,ViewGroup parent){

    convertView = inflater.inflate(R.layout.story_list_page, parent, false);
    ListView listView = (ListView) convertView
            .findViewById(R.id.list_content);
    listView.setVerticalScrollBarEnabled(false);
    Log.d(TAG, "The current page id is " + position + "item id "
            + items.get(position).getId());
    mCurrentPageAdapter = new PageListAdapter(mContext, position);
    listView.setAdapter(mCurrentPageAdapter);
    listView.setOnTouchListener(gestureListener);
    listView.setOnItemClickListener(itemClickListener);

    return convertView;

onItemCLickListner() onItemCLickListner()

OnItemClickListener itemClickListener = new OnItemClickListener() { OnItemClickListener itemClickListener = new OnItemClickListener(){

    @Override
    public void onItemClick(AdapterView<?> adapter, View view,
            int position, long arg3) {
        Log.d("adapter", "Item clicked" + position);
        ContentData item = (ContentData) mCurrentPageAdapter
                .getItem(position);
        Intent detailsIntent = new Intent(mContext, StoryContentActivity.class);
        Log.d(TAG, "looking out for story id "+item.id);
        detailsIntent.putExtra("STORY_ID", item.id);
        mContext.startActivity(detailsIntent);
    }
};  

You pass the same position to the 您将相同的位置传递给

  mCurrentPageAdapter = new PageListAdapter(mContext, position);

in page one your intention for item 1 is one and correct but in page two the new fragment is created and so the position is also 1 and starts from beginning, so add position by number of item in each page for example in page one add by zero in page two add by all items of page one , in page three add by all items of page one and two follow the pattern. 在第一页中,您对第1项的意图是正确的,但在第二页中,将创建新的片段,因此位置也是1,并且从头开始,因此请在每页中按项数添加位置,例如在第一页中按第二页中的零添加到第一页的所有项中,第三页中的第一和第二页的所有项相加。

hope help you 希望对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM