У меня есть набор кнопок, определенных в макете таблицы.Событие нажатия кнопки не запускается
custom_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:id="@+id/tableLayout">
<TableRow
android:layout_weight="1">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/firstBtn"
android:text="F"
android:layout_weight="0.3">
</Button>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/secondBtn"
android:text="S"
android:layout_weight="0.3">
</Button>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thirdBtn"
android:text="T"
android:layout_weight="0.3">
</Button>
</TableRow>
</TableLayout>
</RelativeLayout>
Этот XML устанавливается в качестве макета в пользовательских предупреждений диалога.
Код:
public class CustomDialogPreference extends DialogPreference {
private Button firstBtn = null;
private Button secondBtn = null;
private Button thirdBtn = null;
public CustomDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setPersistent(false);
this.context = context;
setDialogLayoutResource(R.layout.custom_layout);
}
@Override
protected void onBindDialogView(View view) {
firstBtn = (Button)view.findViewById(R.id.firstBtn);
secondBtn = (Button)view.findViewById(R.id.secondBtn);
thirdBtn = (Button)view.findViewById(R.id.thirdBtn);
firstBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Check","First button is clicked"));
}
});
secondBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Check","Second button is clicked"));
}
});
thirdBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Check","Third button is clicked"));
}
});
super.onBindDialogView(view);
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
persistBoolean(positiveResult);
Log.d("Blockout","Dialog close detected");
if(positiveResult)
{
Log.d("Blockout","Save button had been clicked");
}
}
}
Когда открывается диалоговое окно, и я нажимаю на кнопки, я не в состоянии видеть соответствующие сообщения журнала. Я также не получаю исключений с нулевым указателем, поэтому я думаю, что представления устанавливаются и доступны правильно. Любая идея, что мне не хватает?
как вы открыли диалог? поделиться своим кодом –
Я устанавливаю это диалоговое окно на экране предпочтений xml (не через код) .. и открывается диалоговое окно, а некоторые другие элементы в настраиваемом диалоге доступны (я не включал это здесь, поскольку он не имеет отношения к вопрос) – SoulRayder
сделать тост, заменяющий журнал. –