Reputation: 173
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?
Upvotes: 0
Views: 428
Reputation: 16043
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);
//...
Upvotes: 1