列表视图setOnClickListener从列表视图
问题描述:
返回错误的数据你好我使用avocarrot SDK原生广告。我已经在我的列表视图&中成功实现了广告展示效果非常好。但是当我点击listview使用setOnClickListener我得到错误的数据。下面是我的代码..列表视图setOnClickListener从列表视图
avocarrot setlistadapter
avocarrotInstream = new com.avocarrot.androidsdk.AvocarrotInstream(
listAdapter, /* pass your listAdapter */
this, /* reference to your Activity */
"my api key", /* replace with your Avocarrot API Key */
"my placement key" /* replace with your Avocarrot Placement Key */
);
avocarrotInstream.setLogger(true, "ALL");
avocarrotInstream.setSandbox(true);
avocarrotInstream.setLayout(R.layout.avocarrot_feed_row, R.id.avo_container, R.id.feed_title, R.id.feed_description, R.id.feed_icon, R.id.feed_image, R.id.feed_button);
// Bind the created avocarrotInstream adapter to your list instead of your listAdapter
listView.setAdapter(avocarrotInstream);
我onclicklistener
private class Click2 implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Object obj = avocarrotInstream.getItem(position);
String name = ((TextView) view.findViewById(R.id.name)).getText()
.toString();
String status = ((TextView) view.findViewById(R.id.txtStatusMsg))
.getText().toString();
String bitmap = ((FeedItem) feedItems.get(position)).getImge();
Intent in = new Intent(NewBlogStyleHindi.this, SingleActivity.class);
in.setType("text/html");
in.putExtra(TAG_TITLE, name);
in.putExtra("images", bitmap);
in.putExtra(TAG_TEXT, status);
startActivity(in);
}
}
和avocarrot只要列表视图setonclicklistener作为
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
/* get your object from avocarrotInstream for clicked position */
Object obj = avocarrotInstream.getItem(position);
}
});
由于广告排在增加..
答
这是Avocarrot支持团队的Nikos。
我想你已经与我们的支持服务联系我们,但我张贴在这里的答案,以防万一别人有类似的问题。
在你OnItemClickListener,你必须使用对象从Avocarrot适配器,而不是直接从您的ArrayList访问对象。
所以你的情况:
Object obj = avocarrotInstream.getItem(position);
将在正确的位置返回FeedItem和OnItemListener将变为:你为什么不使用`listView.setOnItemClickListener(新CLICK2
private class Click2 implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FeedItem feed = (FeedItem) avocarrotInstream.getItem(position);
String name = feed.getName();
String status = feed.getStatus();
String bitmap = feed.getImge();
Intent in = new Intent(NewBlogStyleHindi.this, SingleActivity.class);
in.setType("text/html");
in.putExtra(TAG_TITLE, name);
in.putExtra("images", bitmap);
in.putExtra(TAG_TEXT, status);
startActivity(in);
}
}
() );'? –
那是我在用,但由于原生广告排增加,所以我得到的数据一个列表项back..if有在整个饲料数据的两个广告,然后我回去使用setOnClickListener 2个列表项数据,你能告诉我如何访问列表视图数据使用此行 Object obj = avocarrotInstream.getItem(position); –
该行有错误吗?我不明白为什么这是行不通的。 –