air*_*rne 1 android android-button android-activity onclicklistener
我的活动上有两个按钮.一个是完美的,一个不是.我似乎无法找到问题.这是代码.该create_profile按钮不起作用.有人可以告诉我为什么吗?
private Button create_profile,select_contact;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_main);
select_contact = (Button)findViewById(R.id.add_contact);
create_profile = (Button)findViewById(R.id.create_button);
select_contact.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
final Uri uriContact = ContactsContract.Contacts.CONTENT_URI;
Intent intentPickContact = new Intent(Intent.ACTION_PICK, uriContact);
startActivityForResult(intentPickContact, PICK_CONTACT);
}
});
create_profile.setOnClickListener(new OnClickListener() {
@SuppressLint("ShowToast")
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), "Pressed", Toast.LENGTH_LONG);
System.out.println("PRessed");
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是xml代码
<Button
android:id="@+id/add_contact"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:text="Add"
android:layout_marginLeft="5dp"
android:layout_marginRight="2dp"
android:textSize="19dp"/>
<Button
android:id="@+id/create_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Create Profile"
android:textSize="18sp"
android:layout_marginTop="8dp"/>
Run Code Online (Sandbox Code Playgroud)
我检查了一切,但似乎无法找到问题.
你好,为什么不显示吐司.Toast代码应该是这样的.
Toast.makeText(getApplicationContext(), "Pressed", Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)