2016-02-18 69 views
3

我通過圖像顯示圖像的圖像在另一個活動中的圖像時,我點擊image.Clickable圖像應該打開另一個活動。請幫助我,我該如何做到這一點。我正在粘貼我已完成的幾行代碼。點擊圖像在列表中應該打開另一個活動的路徑

  ItemHolder holder = itemHolder; 
       holder.imageView.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         String urlstring="This is my service to get the images from server"; 
         String imagestring= messageBean.getImagePath().toString(); 
         imagestring = imagestring.replace("./","/"); 
         urlstring = urlstring+imagestring; 
         // messageBean.getTotalVotes() 
         ((Message) activity).SendImageUrl(urlstring);} 
       }); 

從這條路我想打開另一個活動中的圖像點擊它。

+0

於是呼startService啓動其他活動,並通過它來顯示的東西。 –

+0

你能給我代碼嗎? –

回答

0

爲您的適配器中的每個Imageview設置標籤。

例:

ItemHolder holder = itemHolder; 
    holder.imageView.setTage("your url"); 

    holder.imageView.setOnClickListener(new View.OnClickListener() { 
         @Override 
         public void onClick(View v) { 
          String imagestring= holder.imageView.getTag().toString(); 
          imagestring = imagestring.replace("./","/"); 
          urlstring = urlstring+imagestring; 
          // messageBean.getTotalVotes() 
Intent mIntent = new Intent(yourActivityName.this, classToBelaunched.class); 
mIntent.putStringExtra("url",urlString); 
startActivity(mIntent); 

        }); 
0
holder.setOnClickListener(...){ 
    ... onClick(){ 
Intent intent = new Intent(YourActivity.this, SecondActivity.class); 
intent.putExtra("url", "place your url here"); 
stratActivity(intent); 
    } 
} 

在第二活動寫:

Intent intent = getIntent(); 
String url = intent.getStringExtra("url"); 
0

我不知道該messageBean是什麼,但你可以做的是,豆通入通過意圖捆綁的新活動。像這樣:

ItemHolder holder = itemHolder; 
holder.imageView.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class); 
     myIntent.putExtra("messageBean", messageBean); 
     myIntent.startActivity(); 
    }); 

然後在你打開活動:

public void onCreate(Bundle bundle) { 
    String urlstring="This is my service to get the images from server"; 
    MessageBean messageBean = (MessageBean)bundle.get("messageBean"); 
    String imagestring= messageBean.getImagePath().toString(); 
    imagestring = imagestring.replace("./","/"); 
    urlstring = urlstring+imagestring; 
    // messageBean.getTotalVotes() 
    SendImageUrl(urlString); 
} 
相關問題