Я думаю, что это должно сделать трюк. Я просто добавил if(isset
и добавил конкатенацию к переменным в теле, чтобы отделить PHP от HTML.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: yoursite.com';
$to = 'contact@yoursite.com';
$subject = 'Customer Inquiry';
$body = "From:" .$name."\r\n E-Mail:" .$email."\r\n Message:\r\n" .$message;
if (isset($_POST['submit']))
{
if (mail ($to, $subject, $body, $from))
{
echo '<p>Your message has been sent!</p>';
}
else
{
echo '<p>Something went wrong, go back and try again!</p>';
}
}
?>
View
s раздуты из макета - как ваш пример TextView
- не добавляются к их родительскому ViewGroup
с addView(View child)
, поэтому переопределение этого метода не работает для вас. Вы хотите переопределить addView(View child, int index, ViewGroup.LayoutParams params)
, в результате чего все остальные addView()
перегрузки заканчиваются вызовом.
В этом методе проверьте, является ли добавленный ребенок одним из двух специальных FrameLayout
s. Если это так, пусть класс super
обрабатывает добавление. В противном случае добавьте дочерний элемент в ваш контейнер FrameLayout
.
public class CustomFrameLayout extends FrameLayout {
private final FrameLayout topLayout;
private final FrameLayout containerLayout;
...
public CustomFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.custom, this, true);
topLayout = (FrameLayout) findViewById(R.id.frame_layout_top);
containerLayout = (FrameLayout) findViewById(R.id.frame_layout_child_container);
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
final int id = child.getId();
if (id == R.id.frame_layout_top || id == R.id.frame_layout_child_container) {
super.addView(child, index, params);
}
else {
containerLayout.addView(child, index, params);
}
}
}
getChildCount() == 0
. – comm1x 25 August 2017 в 11:06