2017-06-29 59 views
0

我有一個litview在我的代碼和每個項目有一個edittext與一個按鈕,所以我想要做的是獲得edittext的值,當按下按鈕一個listview的項目。獲取一個列表視圖的EditText值,當它點擊它的項目

我試圖通過聲明它來獲取值,但它返回空值!

public View getView(int i, View view, ViewGroup viewGroup){ 
LayoutInflater linflater = getLayoutInflater(); 
View view1 = linflater.inflate(R.layout.row_view, null); 
final EditText replyfld = (EditText) view1.findViewById(R.id.replyfld); 
final Button sendreplybtn = (Button)view1.findViewById(R.id.sendreplybtn); 

sendreplybtn.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
String thereplyvalue = replyfld.getText().toString(); 
Toast.makeText(MessagesActivity.this, thereplyvalue, Toast.LENGTH_SHORT).show(); 
} 
}); 
} 

請問該做什麼?

+0

什麼返回null?有什麼異常? –

+0

感謝您的評論,它返回空值(意味着什麼都不返回)。 – Ghadeer

+0

我的意思是代碼的哪一行。 –

回答

0

來自pastebin.com/HejVn4bb的代碼。

看起來像調用replytogglebtn.setFavorite(false,true); (Line:101)在onClickListener之前獲取文本是問題,因爲setOnFavoriteChangeListener()清除edittext。

只是在setFavorite之前得到文本(false,true);

+0

非常感謝兄弟。 – Ghadeer

0

您必須在適配器內執行此操作。你能過去它的代碼嗎?

+0

它現在在適配器現在親愛的,這裏是適配器的代碼:https://pastebin.com/HejVn4bb – Ghadeer

+1

這可能是,你有更多的編輯與sam id ..像其他用戶說,請張貼的XML代碼。 –

相關問題