2014-04-12 42 views
0
feed 
      .setOnItemClickListener(new AdapterView.OnItemClickListener() { 
       @Override 
       public void onItemClick(AdapterView<?> parent, View view, 
             int position, long id) { 
        Toast.makeText(getApplicationContext(),"position is "+ position, Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(getApplicationContext(), DetailActivity.class); 
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

        Log.d("listview", "variables: "+ ((Location2) places.get(position)).getName()+" "); 
        Log.d("listview", "variables: "+ ((Location2) places.get(position)).getImage()+" "); 
        Log.d("listview", "variables: "+ ((Location2) places.get(position)).getDiscription()+" "); 
        i.putExtra("name", ((Location2) places.get(position)).getName()); 
        i.putExtra("pic", ((Location2) places.get(position)).getImage()); 
        i.putExtra("disc", ((Location2) places.get(position)).getDiscription()); 

        getApplicationContext().startActivity(i); 
       } 
      }); 

所有的數據是存在的,在日誌中打印出來,但只有當它是位置0startActivity運行在列表視圖的第一個元素,但多數民衆贊成它

+0

logcat的變量發生?無論如何,避免getApplicationContext!使用TopClass.this.startActivity –

+0

是啊所有的LogCat變量都發生了 –

+0

您是否嘗試過改變startActivity調用? –

回答

0

不約十分清楚啓動新活動的問題。如果你只顯示在位置0敬酒的消息,看來,當你點擊位置0

也許,正如馬可的建議onItemClick方法只被調用,您可以試試這個:

feed 
      .setOnItemClickListener(new AdapterView.OnItemClickListener() { 
       @Override 
       public void onItemClick(AdapterView<?> parent, View view, 
             int position, long id) { 
        Toast.makeText(view.getContext(), "position is " + position, Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(view.getContext(), DetailActivity.class); 
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

        Log.d("listview", "variables: " + ((Location2) places.get(position)).getName() + " "); 
        Log.d("listview", "variables: " + ((Location2) places.get(position)).getImage() + " "); 
        Log.d("listview", "variables: " + ((Location2) places.get(position)).getDiscription() + " "); 
        i.putExtra("name", ((Location2) places.get(position)).getName()); 
        i.putExtra("pic", ((Location2) places.get(position)).getImage()); 
        i.putExtra("disc", ((Location2) places.get(position)).getDiscription()); 

        view.getContext().startActivity(i); 
       } 
      }); 
相關問題