![](/img/trans.png)
[英]How to set onclicklistener in lazyadapter->getItem() and launch an activity in onClick Method
[英]How to call a new activity in the OnClickListener () LazyAdapter
我想通過單擊惰性適配器上的圖片來調用新活動,但是為什么在下一行中出現意圖錯誤“構造函數Intent(LazyAdapter,Class)未定義”
// Click on Image
gambar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String strImageID = data.get(position).get("ImageID").toString();
String strImageName = data.get(position).get("ImageName").toString();
String strImagePathFull = data.get(position).get("ImagePathFull").toString();
Intent newActivity = new Intent(LazyAdapter.this,VoteActivity.class); //Line error
newActivity.putExtra("ImageID", strImageID);
newActivity.putExtra("ImageName", strImageName);
newActivity.putExtra("ImagePathFull", strImagePathFull);
startActivity(newActivity); //line error
}
});
我在lazyadapter中調用新活動時做錯了什么步驟。 我計划在LazyList上的圖像可以單擊,然后以更大的圖片顯示一個新活動。 請幫忙,我打錯新活動了嗎? 我應該怎么做才能使該圖像可以單擊LazyList,然后對全尺寸圖像執行,然后進行投票。
它應該是您Activity的上下文,而不是Adapter類,
Intent newActivity = new Intent(YourActivity.this,VoteActivity.class);
代替
Intent newActivity = new Intent(LazyAdapter.this,VoteActivity.class);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.