【发布时间】:2014-09-17 21:41:55
【问题描述】:
这是我将侦听器添加到我的活动文件中的按钮的代码:
get_started_imready = (Button) findViewById(R.id.im_ready);
get_started_imready.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Log.v("BUTTON ACTIVITY ENTERED","hi");
startActivity(new Intent(ThirdActivity.this, SetupPageOne.class));
finish();
}
});
下面是对应xml文件中的按钮代码:
<Button
android:id="@+id/im_ready"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:clickable="true"
/>
这是我的第二个活动的代码:SetupPageOne
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class SetupPageOne extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup_page_one);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.setup_page_one, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
当我尝试在我的 android 设备上运行此代码时,程序运行时没有任何运行时错误,但按钮本身没有响应并且不会切换到第二个活动。
有人知道吗?谢谢!
【问题讨论】:
-
如果您在
onClick()中取消注释您的日志语句,日志会出现吗? -
不,不是,我不知道为什么。
-
也许你应该试试
Log.d看看onClick()是否被触发或检查你的LogCat 设置,默认情况下通常不会显示“详细”级别的日志 -
我什么都试过了。吐司没有被调用,这意味着方法本身没有被调用。这些活动是否也可以作为查看器的片段与它不起作用的任何原因有关?
标签: java android xml button android-activity