I'm trying to get my list view to open up an alert dialog to display information when a person clicks on a selection. I have been trying several different things on the Google Developers website that have to do with this but have yet to come up with a result. Here is my code.
package table.periodic;
import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener;
public class Anions extends Activity { AlertDialog.Builder builder; AlertDialog alertDialog; String[] anions ={ "Acetate", "Bromide", "Carbonate", "Chlorate", "Chloride", "Chlorite", "Chromate", "Cyanide", "Dichromate", "Fluoride", "Hexacyanoferrate(II)", "Hexacyanoferrate(III)", "Hydride", "Hydrogen Carbonate", "Hydrogen Sulfate", "Hydroxide", "Hypochlorite", "Iodide", "Nitrate", "Nitrite", "Oxide", "Perchlorate", "Permanganate", "Peroxide", "Phosphate", "Sulfate", "Sulfide", "Sulfite" }; public void onCreate(Bundle icicle){ super.onCreate(icicle); setContentView(R.layout.anions);
ListView list=(ListView)findViewById(R.id.anionlist);
list.setTextFilterEnabled(true);
ArrayAdapter<String> aa=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, anions);
list.setAdapter(aa);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String itemText = anions[arg2];
new AlertDialog.Builder(Anions.this);
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle(itemText);
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.hydrogen);
}
});
}
}