按钮什么时候不做任何事情

时间:2014-05-15 07:28:09

标签: java android request

MainActivity.java

package com.example.mdpmk1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.widget.Button;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

public class MainActivity extends Activity {

 Button bt, bt2;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);

     bt = (Button) findViewById(R.id.scan);
     bt2 = (Button) findViewById(R.id.getResults);



     bt.setOnClickListener(new OnClickListener() {

         @Override
         public void onClick(View v) {
             // TODO Auto-generated method stub
              // do initiatescan
         }
     });

     bt2.setOnClickListener(new OnClickListener() {

         @Override
         public void onClick(View arg0) {

             Intent intent = new Intent(MainActivity.this, ScanResult.class);
             startActivity(intent);



         }

     });



 }

public void onActivityResult(int requestCode, int resultCode, Intent intent) 
     {
         //super.onActivityResult(requestCode, resultCode, intent);
         if (requestCode == 0) {
             if (resultCode == RESULT_OK) {

             } else if (resultCode == RESULT_CANCELED) {

             }
         }
     }


 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     // Inflate the menu; this adds items to the action bar if it is present.
     getMenuInflater().inflate(R.menu.main, menu);
     return true;
 }

}

IntentIntegrator.java 可以找到HERE

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/appName"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/scan"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/scanClick" />

<Button
    android:id="@+id/getResults"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/getResults" />

</LinearLayout>

Mainfest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mdpmk1"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:debuggable="true"
        android:name="com.example.mdpmk1.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".ScanScreen" />
    <activity android:name=".ScanResults" />
</application>

</manifest>

这是对Aniruddha的回应,他请求此代码帮我解答问题HERE如果有其他人可以告诉我为什么我的按钮2不起作用那将是非常可爱的谢谢。

1 个答案:

答案 0 :(得分:0)

你有什么

<activity android:name=".ScanResults" />

使用意图时

 Intent intent = new Intent(MainActivity.this, ScanResult.class);

ScanResultsScanResult不一样。

如果未找到活动,则应获取ActivityNotFoundException

  

调用startActivity(Intent)或者一个时抛出此异常   其变体失败,因为无法找到Activity执行   给定的意图。

http://developer.android.com/reference/android/content/ActivityNotFoundException.html