2011-02-28 124 views
0

我在我的ListView上有以下ClickListener。我的項目佈局是一個帶有3個TextView的RelativeLayout。我試圖返回列表項的值,但我得到「[email protected] ....」。我究竟做錯了什麼?ClickListener和ListView項目佈局

 itemList=(ListView)findViewById(android.R.id.list); 
     itemList.setTextFilterEnabled(true); 
     itemList.setOnItemClickListener(new OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
       Intent intent = new Intent(); 
       Bundle b = new Bundle(); 
       b.putString("TEXT", ((RelativeLayout) v).getChildAt(position).toString()); 
       intent.putExtras(b); 
       setResult(SUCCESS_RETURN_CODE, intent); 
       finish(); 
      } 
     }); 
+0

[ClickListener如何知道要返回哪些數據?](http://stackoverflow.com/questions/5147239/how-does-a-clicklistener-know-which-data-to-return) – kcoppock 2011-02-28 21:51:48

回答

2

你應該使用TextView.getText()

RelativeLayout relativeLayout = (RelativeLayout) v; 
TextView textView = (TextView) relativeLayout.getChildAt(position); 
b.putString("TEXT", textView.getText()); 
0

b.putString( 「TEXT」,((RelativeLayout的)V).getChildAt(位置)的ToString();而不是嘗試做這個

b.putString( 「TEXT」,(a.getItemAtposition(位置)的ToString);

如果這不起作用,請提供有關error..Hope更多信息這有助於