0

Hy everybody.

I need to verify if the content of a string is null or not. If the string is != null I make a performClick in a imageButton. This click make a inflate of layout in another layout. Then I need to write text in the editText that was inflated, but I can't. Is not possible to do a inflation and write text in editText inflated simultaneously.

Here is my code

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
}

I don't know if you understand my question Thanks for your help.

Ricardo Filipe
  • 435
  • 4
  • 8
  • 24

2 Answers2

1

You'll have to be more specific as to the exact problem with your code, but one possible problem is that you should be using .equals() to compare String values, not the != operator.

Try using the following instead. I like to use

if (sApelido != null && !sApelido.equals(""))
{
    //your logic
}
wsanville
  • 37,158
  • 8
  • 76
  • 101
  • Hy wsanville.I update my question. I also try this way but don't work. If I do only thge inflation only it works. But if i do the inflation and try to write in editText inflated simultaneously don't work :S – Ricardo Filipe Jul 23 '12 at 15:36
  • resolve the problem. I was to get the editText before the if. My code now is if(!sApelido.equals("")){ imbtMore = (ImageButton)findViewById(R.id.se_ivMore); imbtMore.performClick(); apelido = (EditText)findViewById(R.id.sfsn_etStructuredNameApelido); apelido.setText(null); apelido.setText(sApelido); } Thanks for your help anyway :) – Ricardo Filipe Jul 23 '12 at 15:57
0

and to write in the inflated view you could just use something like this :

    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;
    }

then just add the View to your layout or wherever you want to display it.

Slickelito
  • 1,786
  • 20
  • 28
  • Hy Slicklito. Thanks for your reply.I update my question. I also try this way but don't work. If I do only the inflation only it works. But if i do the inflation and try to write in editText inflated simultaneously don't work :S – Ricardo Filipe Jul 23 '12 at 15:37
  • I resolve the problem. I was to get the editText before the if. My code now is if(!sApelido.equals("")){ imbtMore = (ImageButton)findViewById(R.id.se_ivMore); imbtMore.performClick(); apelido = (EditText)findViewById(R.id.sfsn_etStructuredNameApelido); apelido.setText(null); apelido.setText(sApelido); } Thanks for your help anyway :) – Ricardo Filipe Jul 23 '12 at 15:57