तो मैं कुछ शोध किया है, और कोडएंड्रॉयड स्टूडियो में बटन क्लिक करें घटना को जोड़ने का तरीका
private Button buttonname;
buttonname = (Button) findViewById(R.id.buttonnameinandroid) ;
यहाँ
द्वारा एक वस्तु के रूप में आप बटन को परिभाषित करने के बाद
buttonname.setOnClickListener(this); //as I understand it, the "**this**" denotes the current `view(focus)` in the android program
तो मेरी समस्या है आपके OnClick()
घटना ...
समस्या:
जब मैं "इस" में लिखते हैं, कहते हैं:
setOnClickListener (Android.View.view.OnClickListener) in View cannot be applied to (com.helloandroidstudio.MainActivity)
मुझे नहीं पता क्यों?
यहाँ जावा फाइल से कोड है
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private Button btnClick;
private EditText Name, Date;
private TextView msg, NameOut, DateOut;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnClick = (Button) findViewById(R.id.button) ;
btnClick.setOnClickListener(this);
Name = (EditText) findViewById(R.id.textenter) ;
Date = (EditText) findViewById(R.id.editText) ;
msg = (TextView) findViewById(R.id.txtviewOut) ;
NameOut = (TextView) findViewById(R.id.txtoutName) ;
DateOut = (TextView) findViewById(R.id.txtOutDate) ;
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
public void onClick(View v)
{
if (v == btnClick)
{
if (Name.equals("") == false && Date.equals("") == false)
{
NameOut = Name;
DateOut = Date;
msg.setVisibility(View.VISIBLE);
}
else
{
msg.setText("Please complete both fields");
msg.setVisibility(View.VISIBLE);
}
}
return;
}
:
और अंदर
MainActivity
विधिonClick()
, इस तरह ओवरराइड क्या आप अपने उत्तर में कोई विवरण दे सकते हैं? – Patrick