Loading layout xml failed

gallardo87

New Member
I think I should present the whole layout structure so that you can figure out where is the problem. I am new to Android programming and am not sure what I am doing is right. I have main.xml loaded with listview. Then I have a menu and when pressing the menu, I load add.xml to add a new list to the listview. It is as follows and is working fine.\[code\]final View addView = getLayoutInflater().inflate(R.layout.add, null); new AlertDialog.Builder(this).setTitle("New Tracker").setView(addView) .setPositiveButton("ADD", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { addWord((TextView) addView.findViewById(R.id.IDeditText)); } }).setNegativeButton("Cancel", null).show();\[/code\]add.xml has an EditText view. When the user taps on the EditText, I would like to load another XML layout called description.xml. That is done as follows -\[code\]private void add() { final View addView = getLayoutInflater().inflate(R.layout.add, null); EditText DescEditTxt = (EditText) addView.findViewById(R.id.descriptionEdit); if(DescEditTxt != null) { DescEditTxt.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { final View descriptionView = getLayoutInflater().inflate(R.layout.description, null); setContentView(descriptionView); } }); } new AlertDialog.Builder(this).setTitle("New Tracker").setView(addView) .setPositiveButton("ADD", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { addWord((TextView) addView.findViewById(R.id.IDeditText)); } }).setNegativeButton("Cancel", null).show();}\[/code\]When the user has a focus on the EditText view, I tried to load the description.xml but The program crashed at \[code\]setContentView(descriptionView);\[/code\]My queries are
  • Does that make sense with what I am doing? And is there any better approach for this?
  • What could be the problem due to which the program crashed?
 
Back
Top