-1

这是一个非常幼稚的问题。我想从两个不同的按钮调用两个不同的类。下面的代码工作正常,但GalleryView.class只执行一次。我调用SelectImage.class的那一刻,这是一个对话似乎工作正常,但另一个只显示一次。请对此有所了解.

感谢和问候阿维吉特保罗

private Button button,button1;
public static String filename = "prefs";
SharedPreferences prefs;

public vp_default() 
{
    // TODO Auto-generated constructor stub
}

 public void onCreate(Bundle savedInstanceState) 
    {       
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);   
        prefs = getSharedPreferences(filename,0);

        button  = (Button)findViewById(R.id.view_gallery_button);
        button.setOnClickListener(this);

        button1  = (Button)findViewById(R.id.sel_image_button);
        button1.setOnClickListener(this); 

    }

    @Override
    public void onClick(View v) 
    {
            String setPhnNo = "9231512345";
            boolean stat = prefs.contains(setPhnNo);

            switch(v.getId())
            {
             case R.id.view_gallery_button:     
                    if(stat!=false)
                    {

                        startActivity(new Intent(getApplicationContext(), VirtualPainterActivity.class));

                    }
                    else
                    {
                        startActivity(new Intent(getApplicationContext(), GalleryView.class));


                    }
                break;
                case R.id.sel_image_button: 
                        startActivity(new Intent(getApplicationContext(), SelectImage.class));

                break;
            }

    }

}

//manifest.xml

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

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
         <activity
            android:label="@string/app_name"
            android:name=".vp_default" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity> 
        <activity
            android:label="@string/app_name"
            android:name=".VirtualPainterActivity"
            android:theme="@android:style/Theme.Dialog">
            <intent-filter >
                <action android:name="android.intent.action.vp_regn" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:name=".GalleryView">
            <intent-filter >
                <action android:name="android.intent.action.vp_gview" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:name=".SelectImage" >
            <intent-filter >
                <action android:name="android.intent.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:label="@string/app_name"
            android:name=".ViewImage">
            <intent-filter >
                <action android:name="android.intent.vp_view_img" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
4

2 回答 2

1

终于解决了……问题出在清单文件中……我已经两次声明了“action.MAIN”……并且按钮不断迭代默认活动……感谢大家的时间……@ Perroloco @Akki @Zaz Gmy

于 2012-05-13T18:33:49.013 回答
0

我不知道错误是什么,但请尝试以下操作:

像这样将监听器直接放在 onCreate 方法中

button1.setOnClickListener(new OnClickListener(){
   @Override
    public void onClick(View v) 
    {
    YOUR CODE FOR BUTTON 1
    }


});

对按钮做同样的事情;)

于 2012-05-03T13:30:03.627 回答