0

我正在构建一个 nfc 读取标签应用程序。但我找不到设置布局。
setContentView(R.layout.read)中的问题 ; 和
txtRead = (TextView) findViewById(R.id.txt_read);

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 try{
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.read);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.read);

     //    nfcAdapter = NfcAdapter.getDefaultAdapter(null);
     //    detectedTag =getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG);


        txtRead  = (TextView) findViewById(R.id.txt_read);

        pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, 
                new Intent(this,getClass()).
                addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

        IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
        IntentFilter filter2     = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
       // readTagFilters = new IntentFilter[]{tagDetected,filter2};
        Toast.makeText(this, "no Exception caught in on create", Toast.LENGTH_LONG).show();
 }
 catch(Exception e) { Toast.makeText(this, "Exception caught in on create", Toast.LENGTH_LONG).show(); }
    }
4

1 回答 1

0

稍后尝试 setContentView:

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.read);
    setContentView(R.layout.read);

请检查您导入的 R。也许您导入了 android.R 而不是从包中导入了 R。

于 2013-06-01T04:47:42.463 回答