Question

I have set up a ViewFlipper in my Android application that will host a series of windows to display messages. Each window should correspond to a different set of messages, similar to multiple open chats. For each window I am using the same window.xml view to bring the view onto the screen, it also has the variable for the EditText need to edit.

For reference I am creating and adding children as follows:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
        detector = new GestureDetector(this,this);
        setContentView(R.layout.viewflip);
        flipper = (ViewFlipper) findViewById(R.id.viewflip);

        addChild(flipper);
        addChild(flipper);
}

private void addChild(ViewFlipper flip){
     int index=0;
     View view = getView();

     if(flip.getChildCount()==0){
         flip.addView(view,index);
     }
     else{
     flip.addView(view,flip.getChildCount());
 }

 }

 private View getView(){
     LayoutInflater inflater = this.getLayoutInflater();
     View view = inflater.inflate(R.layout.window, null);        
     return view;
 }

As you can see, I am basically duplicating the view (I'm not sure this is the proper approach to my design). So if I were to do something in the onCreate function after adding the children, such as

EditText messageHistoryText = (EditText) findViewById(R.id.messageHistory);         
        messageHistoryText.append("Testing :\n");

I see the text on both windows.

I thought that something like this would be better:

View v1 = flipper.getChildAt(1);
        EditText messageHistoryText2 = (EditText) v1.findViewById(R.id.messageHistory);
        messageHistoryText2.append("Testing2 :\n");

but when I use that one, I don't see anything at all. Perhaps there is a mistake on adding the children. Perhaps I can't use the same view, or perhaps I am selectively changing an EditText in an incorrect way.

Tips?

Was it helpful?

Solution

Try the following,

EditText messageHistoryText = flip.getChildAt(j).findViewById(R.id.messageHistory);

where j represents the child position in ViewFlipper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top