Reputation:
I get this error code The constructor TextView(new View.OnClickListener(){}) is undefined
please help me this is my code, its had me stumped for days now.
`package com.example.tgtidea;
public class FrontPage extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_front_page);
Button btn1 = (Button)findViewById(R.id.button1);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText comment = (EditText)findViewById(R.id.editText1);
String comment1 = comment.getText().toString();
TextView textView = new TextView();
textView.setTextSize(40);
textView.setText(comment1);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.front_page, menu);
return true;
}
}
`
This not all of my code but it is most of it. did some research and it looked like some other people had a similar problem except with Intent instead of Text View. I'm a pretty young programmer i'm only 14 so excuse my ignorance. Thank you for your help.
Upvotes: 3
Views: 2761
Reputation: 133560
Change this
TextView textView = new TextView();
to
TextView textView = new TextView(FrontPage.this);
But your textView is not attached to activity. Have a LinearLayout or RelativeLayout in activity_frot_page
, initialize it and add textView to it or have textView in activity_front_page
initialize it and set text to textView
http://developer.android.com/reference/android/widget/TextView.html
Look at the public constructors in the above link
Upvotes: 3
Reputation: 2705
try something like:
mCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new FatchItemsTask().execute();
}
});
Upvotes: 0