我的主表单上有三个按钮。我加了第三个。当我尝试使用findViewById分配按钮时,返回null。
这是我的main.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1" android:clickable="false">
<TextView android:layout_width="wrap_content"
style="@style/TitleText"
android:text="@string/app_name"
android:background="@drawable/black_gradient">
</TextView>
<Button android:id="@+id/btnvalidatemark"
android:background="@drawable/grad_btn_green"
style="@style/ButtonText" android:text="@string/validate_mark_button">
</Button>
<Button android:id="@+id/btncheckregistry"
android:background="@drawable/grad_btn_yellow"
style="@style/ButtonText" android:text="@string/check_registry_button">
</Button>
<Button android:id="@+id/btnregcreds"
android:background="@drawable/grad_btn_red"
style="@style/ButtonText" android:text="@string/registry_config_button">
</Button>
</TableLayout>
这是我的活动代码:
package uid.android.uidchecker;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.util.Log;
public class UIDCheckerActivity
extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
Button validatebutton = (Button) findViewById(R.id.btnvalidatemark);
Button checkbutton = (Button) findViewById(R.id.btncheckregistry);
Button setcredbutton = (Button) findViewById(R.id.btnregcreds);
validatebutton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(UIDCheckerActivity.this, SelectFileActivity.class);
i.putExtra("func", "validatemark");
startActivity(i);
}
});
checkbutton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
//Intent i = new Intent(UIDCheckerActivity.this, validatemark.class);
Intent i = new Intent(UIDCheckerActivity.this, SelectFileActivity.class);
i.putExtra("func", "checkregisrty");
startActivity(i);
}
});
setcredbutton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(UIDCheckerActivity.this, RegistryCredsActivity.class);
startActivity(i);
}
});
}
}