2017-06-29 46 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代码。 –

相关问题