看板 AndroidDev 關於我們 聯絡資訊
最近遇到button onclick完全無反應 但button可以改文字xx.setText("88888"); 一整個無頭緒 麻煩大家幫看一下問題所在 ----------------------layout-------------------------- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/restaurant_detail_container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".restaurantDetailActivity" tools:ignore="MergeRootFrame" android:clickable="false"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ok" android:id="@+id/button01" android:layout_gravity="right|top" android:clickable="false" android:enabled="true" android:longClickable="false" android:focusable="false" /> <TextView android:layout_width="108dp" android:layout_height="35dp" android:text="height:" android:id="@+id/textView" android:layout_gravity="left|top" android:textSize="30dp" /> <EditText android:layout_width="151dp" android:layout_height="wrap_content" android:inputType="numberSigned" android:ems="10" android:id="@+id/editText" android:layout_gravity="center_horizontal|top" android:enabled="true" android:clickable="true" android:editable="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_gravity="left|center_vertical" android:textSize="12dp" android:enabled="true" /> </FrameLayout> _-----------------------------code---------------------------------- public class restaurantDetailActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d("test", "point2"); setContentView(R.layout.activity_restaurant_detail); // Show the Up button in the action bar. getSupportActionBar().setDisplayHomeAsUpEnabled(true); if (savedInstanceState == null) { // Create the detail fragment and add it to the activity // using a fragment transaction. Bundle arguments = new Bundle(); arguments.putString(restaurantDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(restaurantDetailFragment.ARG_ITEM_ID)); restaurantDetailFragment fragment = new restaurantDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() .add(R.id.restaurant_detail_container, fragment) .commit(); } Button xx=(Button)findViewById(R.id.button01); xx.setText("88888"); xx.setOnClickListener(new Button.OnClickListener(){ @Override public void onClick(View v) { Button xx=(Button)findViewById(R.id.button01); Log.d("test", "point3") doSomething(v); } }); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { NavUtils.navigateUpTo(this, new Intent(this, restaurantListActivity.class)); return true; } return super.onOptionsItemSelected(item); } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.176.197 ※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1435921328.A.360.html
okskygo: clickable 改成true ? 07/03 19:34
fish0112: button你把可按可長按都f掉了這....................... 07/03 20:43
fish0112: 放button做啥呀XD 07/03 20:43
JULONE780701: 你知道自己在幹嘛嗎XD 07/03 21:28
egaryer: 幹嘛按鈕findviewbyid兩次XDD 07/03 22:35
ID113: 因為沒f也無用 只是亂改而已 07/03 22:45