Basically, I'm trying to show an AlertDialog which contains a ListView that has to get the data from an ArrayList when I press an item on mt Customized Spinner. The codes are use are below one by one in order of makeAndShowDialogBox function,setOnItemSelectedListener and dialog.xml :
makeAndShowDialogBox :
private void makeAndShowDialogBox() {
AlertDialog.Builder myDialogBox = new AlertDialog.Builder(this);
final LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View dialogView = layoutInflater.inflate(R.layout.dialog, null);
ListView listView = (ListView) findViewById(R.id.listDialog);
ListAdapter adapter = new ArrayAdapter<String>(ActivityWithCustomizedSpinner.this,android.R.layout.simple_list_item_1, carNames);
listView.setAdapter(adapter);
// Set three option buttons
myDialogBox.setPositiveButton("Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// whatever should be done when answering "YES" goes
// here
}
});
myDialogBox.setView(dialogView);
myDialogBox.show();
}
setOnItemSelectedListener
spin.setAdapter(new MySpinnerAdapter(this, R.layout.spinner_layout,
SpinnerValues));
spin.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
if (isDefaultSelection) {
isDefaultSelection = false;
}else{
carNames = brand.getChildCarNames(brand.getListDataHeader().get(position));
makeAndShowDialogBox();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@string/activity3_name" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listDialog">
</ListView>
</LinearLayout>
However, as soon as I select an item on my Spinner my application crashes. Can anybody see the issue?
No comments:
Post a Comment