Let’s say I have a listView with some formulas like this:
((A * 2 + B * 3 + PF * 5) / 10)
When I click on it I would like to change the letters to EditTexts, so I split this String then, if it is a letter I should replace it by an EditText, so, what should I use to make this happen? I mean, can I have an activity loaded on a “Dialog Style” window? Or I can make this work with Simple Dialog?
I’ve tried this, but it gets error when adding the view(NullPointerException)
lsView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> aView, View view,
int i, long l) {
Dialog dialogFormula = new Dialog(NotasActivity.this); //"Parent" activity
dialogFormula.setTitle("Title");
LinearLayout layout = (LinearLayout)findViewById(R.id.DialogLayout);
String[] lines = materias.get(i).getFormula().split(" ");
for (String s : lines) {
if (s.compareTo("PARTIC") == 0) {
EditText edtPartic = new EditText(dialogFormula.getContext));
layout.addView(edtPartic);
} else if (s.contains("A") && s.compareTo("A") != 0) {
} else if (s.compareTo("B") == 0) {
} else if (s.compareTo("C") == 0) {
} else if (s.compareTo("D") == 0) {
} else if (s.compareTo("E") == 0) {
} else if (s.compareTo("F") == 0) {
} else if (s.compareTo("G") == 0) {
} else if (s.compareTo("H") == 0) {
} else if (s.compareTo("I") == 0) {
} else if (s.compareTo("PF") == 0) {
}
}
dialogFormula.setContentView(layout);
return false;
}
});
dialog_formula.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/DialogLayout">
<TextView
android:id="@+id/txtMateriaDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/txtFormulaDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
I suggest you make a custom dialog class.
Then in your Activity all you have to run is