C
CSharper
Neues Mitglied
- 0
Wieso bekomme ich in immer eine NullPointerReference Exception?
Meine Clickmethode, die ein Custom Dialog aufrufen soll:
Und hier das Layout für den custom dialog!
Meine Clickmethode, die ein Custom Dialog aufrufen soll:
PHP:
/* Register btn_newRoute in onCreate() */
ImageView open_add_new_car_diolog_btn = (ImageView) findViewById(R.id.add_new_car_btn);
open_add_new_car_diolog_btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick( View v )
{
/*
* custom dialog Add new car dialog
*/
final Dialog add_new_car_dialog = new Dialog(CarsActivity.this);
add_new_car_dialog.setContentView(R.layout.add_new_car_layout);
add_new_car_dialog.setTitle(getResources().getString(R.string.add_new_car_popup_Title));
add_new_car_dialog.show();
// Set custom dialog items
TextView make_lbl = (TextView) add_new_car_dialog.findViewById(R.id.Make_lbl);
make_lbl.setText(R.string.make_lbl);
TextView mileage_lbl = (TextView) add_new_car_dialog.findViewById(R.id.Milage_lbl);
mileage_lbl.setText(R.string.mileage_lbl);
TextView model_lbl = (TextView) add_new_car_dialog.findViewById(R.id.Model_lbl);
model_lbl.setText(R.string.model_lbl);
EditText makeEditText = (EditText) add_new_car_dialog.findViewById(R.id.edit_make_txt);
makeEditText.setText(R.string.add_new_car_make_editText);
EditText modelEditText = (EditText) add_new_car_dialog.findViewById(R.id.edit_model_txt);
modelEditText.setText(R.string.add_new_car_model_editText);
EditText mileageEditText = (EditText) add_new_car_dialog.findViewById(R.id.edit_mileage_txt);
mileageEditText.setText(R.string.add_new_car_mileage_editText);
/* Register btn_newRoute in onCreate() */
ImageView add_new_car_ok_btn = (ImageView) findViewById(R.id.add_new_car_ok_btn);
add_new_car_ok_btn.setOnClickListener(new OnClickListener()
{
public void onClick( View v )
{
// ToDo: Code after Click
Toast.makeText(CarsActivity.this, "add_new_car_ok_btn is clicked!", Toast.LENGTH_SHORT).show();
}
});
/* Register btn_newRoute in onCreate() */
ImageView add_new_car_cancel_btn = (ImageView) findViewById(R.id.add_new_car_cancel_btn);
add_new_car_cancel_btn.setOnClickListener(new OnClickListener()
{
public void onClick( View v )
{
// ToDo: Code after Click
Toast.makeText(CarsActivity.this, "add_new_car_cancel_btn is clicked!", Toast.LENGTH_SHORT).show();
}
});
}
});
Und hier das Layout für den custom dialog!
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/add_new_car_layout_row1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/Make_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/make_lbl" />
<EditText
android:id="@+id/edit_make_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="make" />
</TableRow>
<TableRow
android:id="@+id/add_new_car_layout_row2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/Model_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/model_lbl" />
<EditText
android:id="@+id/edit_model_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:gravity="left"
android:text="model" />
</TableRow>
<TableRow
android:id="@+id/add_new_car_layout_row3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/Milage_lbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:gravity="center"
android:text="@string/mileage_lbl" />
<EditText
android:id="@+id/edit_mileage_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:inputType="number"
android:text="mileage" />
</TableRow>
<TableRow
android:id="@+id/add_new_car_layout_row4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/add_new_car_ok_btn"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:src="@drawable/custom_dialog_ok" />
<ImageView
android:id="@+id/add_new_car_cancel_btn"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_weight="1"
android:src="@drawable/custom_dialog_cancel" />
</TableRow>
</TableLayout>
Zuletzt bearbeitet: