0

大家好。

我需要验证字符串的内容是否为空。如果字符串是 != null 我在 imageButton 中创建一个 performClick。此单击使另一个布局中的布局膨胀。然后我需要在膨胀的editText中写入文本,但我不能。不可能同时膨胀并在 editText 中写入文本。

这是我的代码

if(sApelido != ""){
         inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         b = (LinearLayout)inflater.inflate(R.layout.socio_form_structured_name,null);
         lLayout = (LinearLayout)findViewById(R.id.main_layout_id7);
         lLayout = (LinearLayout)findViewById(R.layout.socio_form_structured_name);
         lLayout.addView(b);




        apelido.setText(null);      //Write in one of the editText's that was inflated
    apelido.setText(sApelido);  //apelido is a editText that belongs to LinearLayout b
}

我不知道你是否理解我的问题谢谢你的帮助。

4

2 回答 2

1

您必须更具体地了解代码的确切问题,但一个可能的问题是您应该使用.equals()比较字符串值,而不是!=运算符。

尝试改用以下内容。我喜欢用

if (sApelido != null && !sApelido.equals(""))
{
    //your logic
}
于 2012-07-23T15:19:51.317 回答
0

并在膨胀的视图中写你可以使用这样的东西:

    public View displayEditText(){
    View v = getLayoutInflater().inflate(R.layout.edit_text_layout, null);
    EditText editText = (EditText) v.findViewById(R.id.edit_text);
    editText.setText(sApelido)
    return v;
    }

然后只需将视图添加到您的布局或您想要显示它的任何位置。

于 2012-07-23T15:23:20.367 回答