2012-07-02 42 views
0

我的列表視圖是從網上資源分析,但我不能讓列表視圖的圖片src傳遞給單個列表項的Android的ListView圖像的onclick解析

SingleMenuItemActivity

static final String KEY_SONG = "song"; 
static final String KEY_ARTIST = "artist"; 
static final String KEY_THUMB_URL = "thumb_url"; 
static final String KEY_DURATION = "duration"; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.libraryonclick); 

    // getting intent data 
    Intent in = getIntent(); 

    // Get XML values from previous intent 
    String song = in.getStringExtra(KEY_SONG); 
    String artist = in.getStringExtra(KEY_ARTIST); 
    String thumb_url = in.getStringExtra(KEY_THUMB_URL); 
    String duration = in.getStringExtra(KEY_DURATION); 


    // Displaying all values on the screen 
    TextView lblSong = (TextView) findViewById(R.id.textView1); 
    TextView lblArtist = (TextView) findViewById(R.id.textView2); 
    Drawable imgThumb = ((ImageView)findViewById(R.id.onclickthumb)).getDrawable(); // thumb image 
    TextView lblDuration = (TextView) findViewById(R.id.textView3); 

    Button link3Btn = (Button)findViewById(R.id.button1); 
    link3Btn.setOnClickListener(new View.OnClickListener() 
    { 
     public void onClick(View v) 
     { 
      Uri uri = Uri.parse("http://google.com"); 
      startActivity(new Intent(Intent.ACTION_VIEW, uri)); 
     } 
    }); 

    lblSong.setText(song); 
    lblArtist.setText(artist); 
    lblDuration.setText(duration); 
    imgThumb.setImageResource(thumb_url); 

    //Maybe more code here? 
} 

ListViewActivity

public class CustomizedListView extends Activity { 
// All static variables 
static final String URL = "http://dl.dropbox.com/u/48258247/music.xml"; 
// XML node keys 
static final String KEY_SONG = "song"; // parent node 
static final String KEY_ID = "id"; 
static final String KEY_TITLE = "title"; 
static final String KEY_ARTIST = "artist"; 
static final String KEY_DURATION = "duration"; 
static final String KEY_THUMB_URL = "thumb_url"; 

ListView list; 
LazyAdapter adapter; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.library); 


    ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); 

    XMLParser parser = new XMLParser(); 
    String xml = parser.getXmlFromUrl(URL); // getting XML from URL 
    Document doc = parser.getDomElement(xml); // getting DOM element 

    NodeList nl = doc.getElementsByTagName(KEY_SONG); 
    // looping through all song nodes <song> 
    for (int i = 0; i < nl.getLength(); i++) { 
     // creating new HashMap 
     HashMap<String, String> map = new HashMap<String, String>(); 
     Element e = (Element) nl.item(i); 
     // adding each child node to HashMap key => value 
     map.put(KEY_ID, parser.getValue(e, KEY_ID)); 
     map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE)); 
     map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST)); 
     map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION)); 
     map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL)); 

     // adding HashList to ArrayList 
     songsList.add(map); 
    } 


    list=(ListView)findViewById(R.id.list); 

    // Getting adapter by passing xml data ArrayList 
    adapter=new LazyAdapter(this, songsList);   
    list.setAdapter(adapter); 


    // Click event for single list row 


    list.setOnItemClickListener(new OnItemClickListener() { 

     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 
      // getting values from selected ListItem 
      String song = ((TextView) view.findViewById(R.id.title)).getText().toString(); 
      String artist = ((TextView) view.findViewById(R.id.artist)).getText().toString(); 
      String thumb_url = ((TextView) view.findViewById(R.id.list_image)).getText().toString(); 
      String duration = ((TextView) view.findViewById(R.id.duration)).getText().toString(); 

      // Starting new intent 
      Intent in = new Intent(CustomizedListView.this, org.scouts.library.SingleMenuItem.class); 
      in.putExtra(KEY_SONG, song); 
      in.putExtra(KEY_ARTIST, artist); 
      in.putExtra(KEY_THUMB_URL, thumb_url); 
      in.putExtra(KEY_DURATION, duration); 
      startActivity(in); 

     } 
    });  
} 

我想我需要通過圖像加載程序類解析也許

+0

想要顯示圖像嗎? – Praveenkumar

+0

是的,我想要顯示圖像 – SquiresSquire

回答

1

你可以簡單地嘗試這一個 -

URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464"); 
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
imageView.setImageBitmap(bmp); 

創建一個ImageViewCustomizedListViewoncreate()方法意圖通過從主叫接收文件的URL路徑。並將其粘貼到下面的代碼中並嘗試。

然後,看看this示例

+0

它會出現添加到'imgThumb' – SquiresSquire

+0

上面的代碼或示例? – Praveenkumar

+0

你一個,但我修好了,我希望:P – SquiresSquire