Im opening a ListActivity with an xml called list with a ListView named list. I have an array adapter set up and working in another activity (not a list activity though, just a normal activity) and it all works fine. When I try to open this list activity though, I get an error saying that I need a ListView with the id android.R.id.list. I have that ListView though. What is my problem?
Code for my AlertDialog I am trying to get to work.
public void onListItemClick(ListView parent, View v, int position,
long id)
{
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle(getText(position));
ImageView image = (ImageView) alertDialog.findViewById(R.id.image);
image.setImageResource(R.drawable.hydrogen);
}
and this was another code i had trying to get it to work
public void onListItemClick(ListView parent, View v, int position,
long id) {
new AlertDialog.Builder(Anions.this);
alertDialog.setContentView(R.layout.custom_dialog);
alertDialog.setTitle(anions[position]);
ImageView image = (ImageView) alertDialog.findViewById(R.id.image);
image.setImageResource(R.drawable.hydrogen);
alertDialog.setButton("Done", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
return;
}
}
);
alertDialog.show();
}
Ok. So I finally found what I needed after going through who knows how many sites. Anyways here is the code that finally worked for anyone else out there who runs into a problem like this.
my final code will probably vary from this but this works. For more information about this go to http://www.androidear.com/developers/how-to-display-a-custom-dialog-in-your-android-application/comment-page-1/#comment-1570