1

I am using merge adapter to merge two custom cursor adapters in android.I could not find clicked section to get data from my custom cursor adapter.How can I get adapter object when listview clicked?. I tried following way in my onitemclick of listview. But it does not print "clicked on mention question section" text.But it returns android.content.ContentResolver$CursorWrapperInner@41b9a638.How can I find which section is clicked in listview?

if (parent.getAdapter().getItem(position) instanceof FeedMentionQuestionAdapter) {
        LivLog.info(getClass(), "clicked on mention question section  ");

    }
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
BABU K
  • 917
  • 13
  • 35

1 Answers1

1

How can I get adapter object when listview clicked?

You need to hold onto your own adapter, or call getAdapter() on your ListView.

But it returns android.content.ContentResolver$CursorWrapperInner@41b9a638

Presumably, you put a CursorAdapter in the MergeAdapter.

Also, getItem() will never return an adapter. It returns items. If you are trying to determine the adapter that handles a particular position, call getAdapter().

How can I find which section is clicked in listview?

If you are referring to SectionIndexer, then sections are not clicked.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I tried following steps to find which section clicked on listview.But I could not find the section which I clicked. Step 1: mergeadapter.getAdapter(position) -> but it returns "com.liv.network.adapter.FeedQuestionCursorAdapter@429867c0" as result.I used FeedQuestionCursorAdapter as second part of merge adapter.It always returns "com.liv.network.adapter.FeedQuestionCursorAdapter@429867c0" , when I click on the first part of the mergeadapter .And first part of the mergeadapter is FeedMentionQuestionAdapter. – BABU K May 17 '14 at 06:29
  • Step 2: if(lvFeedquestions.getAdapter() instanceof FeedMentionQuestionAdapter ){ LivLog.info(getClass(), "mention stanza "); }else if(lvFeedquestions.getAdapter() instanceof FeedQuestionCursorAdapter){ LivLog.info(getClass(), "general stanza "); }else{ LivLog.info(getClass(), "something went wrong....."); } – BABU K May 17 '14 at 06:29
  • But it always returns "something went wrong....." as a log message. Please suggest , How can I solve this problm. I want to determine which adapter is clicked? – BABU K May 17 '14 at 06:30
  • @BABUK: I have no idea. – CommonsWare May 19 '14 at 13:42
  • Is there any other solution to find adapter view clicked? – BABU K May 19 '14 at 13:50
  • @BABUK: I cannot make sense of the code that you pasted into the comments. I do not have any of the code where you are creating this `MergeAdapter`. I have no way to help you further at this point. If you feel that this is a possible bug in `MergeAdapter`, create a project that demonstrates the bug, and [file an issue](https://github.com/commonsguy/cwac-merge/issues?state=open) with a link to the project and steps for reproducing the problem. – CommonsWare May 19 '14 at 14:00
  • ,I will do as you said. – BABU K May 19 '14 at 14:06