2013-05-03 22 views
0
List<ListItem> items = new ArrayList<ListItem>(); 
. 
. 
. 
. 
protected void onListItemClick(ListView l, View v, int position, long id) 
{ 

    //super.onListItemClick(l, v, position, id); 
    Toast.makeText(ListPage.this, items[position].sid, Toast.LENGTH_SHORT).show(); 
} 

Toast出現錯誤,錯誤提示「類型的表達式必須是數組類型,但它解析爲List [ListItems]」。需要知道wat的吐字的正確寫法是Toast的語法錯誤

回答

1

你必須使用String.valueOf()來顯示int的值。

Toast.makeText(ListPage.this, String.valueOf( items.get(position)), Toast.LENGTH_SHORT).show(); 
+2

其列表不是數組 – Raghunandan 2013-05-03 11:19:00

+0

@AbhijeetLimaye:對我的答案! – 2013-05-03 11:56:05

2

更換

items[position].sid 

通過

items.get(position).sid //Assuming sid is a type of String 
0

使用

Toast.makeText(ListPage.this, items.get(position).sid, Toast.LENGTH_SHORT).show(); 

不知道什麼sid你的情況

public static Toast makeText (Context context, CharSequence text, int duration) 

參數

  • context:要使用的上下文。通常你的應用程序或活動對象。
  • text:要顯示的文字。可以是格式化文本。
  • duration:顯示消息的時間。無論是LENGTH_SHORT或LENGTH_LONG

Android的上祝酒

文檔查看文檔

使用具有索引位置顯示吐司數組列表的GET方法。

ArrayList<String> mystring = new ArrayList<String>(); 
mystring.add("hello"); 
Toast.makeText(ListPage.this, mystring.get(0).toString(), Toast.LENGTH_SHORT).show(); 
+0

嘿,謝謝@Raghunandan! – 2013-05-03 11:55:14

+0

如果答案有助於接受答案 – Raghunandan 2013-05-03 12:38:24