Question

I'm trying to create dialog inside of onitemclicklistener.

public void onItemClick(AdapterView<?> av, View view, int position, long arg3) {                
    String data = values[position];
    Dialog d = new Dialog(null);
    TextView t = new TextView(null);
    t.setText(data);
    d.setTitle("Okey!");
    d.show();
}

There is no problem with other things. Problem is dialog. I know because when I remove dialog everything is done. I've looked here. That say something about context class. I'm newbie and I can't get what is that. What is the problem? and how can i use dialog, right?

Was it helpful?

Solution

Both Dialog and TextView constructors should be passed a Context object, but you are passing them null.

Since your activity extends Context, you may pass an instance of your activity.

Assuming the name of your activity is MainActivity then you would do this:

Dialog d = new Dialog(MainActivity.this);
TextView t = new TextView(MainActivity.this);
//...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top