无法使用现有布局设置内容

时间:2013-06-01 03:55:31

标签: android layout nfc oncreate

我正在构建一个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(); }
    }

1 个答案:

答案 0 :(得分:0)

稍后尝试setContentView:

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

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