按钮不起作用,没有给出错误

时间:2014-11-16 19:12:20

标签: java android eclipse

我正在开发一个新的应用程序,并复制了我的其他工作应用程序的一些代码。错误日志和问题日志不会给我任何错误,但是当我按下按钮(test / test1 / test2)时,什么也没发生。

MenuScreen.java:

package com.example.random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class MenuScreen extends Activity {  

    @Override
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);



        findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d("DEBUG", "test");
                Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
                startActivityForResult(intent, 0);
            }
        });


        findViewById(R.test1).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Log.d("DEBUG", "test1");
                Intent intent = new Intent(MenuScreen.this, FotoMaker.class);

            }
        });

        findViewById(R.test2).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Log.d("DEBUG", "test2");
                Intent intent = new Intent(MenuScreen.this, FotoMaker.class);

            }
        });



        findViewById(R.id.verlaat_app).setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Log.d("DEBUG", "test3");
                MenuScreen.this.finish();
            }
        });
    }
}

MenuScreen.java:

package com.example.random;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;


public class FotoMaker extends Activity 
    {
    ImageView iv;


    @Override
    protected void onCreate(Bundle savedInstanceState) 
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.testpic);

        iv = (ImageView) findViewById(R.id.imageView);
        Button btn = (Button) findViewById(R.id.testpic);
        btn.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick (View v){
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 0);

            }
        });
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data)
        {
            if(requestCode == 0)
            {
                Bitmap theImage = (Bitmap) data.getExtras().get("data");
                iv.setImageBitmap(theImage);
            }
        }

    }

1 个答案:

答案 0 :(得分:1)

检查这个答案我做了一些修改......

package com.example.random;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

public class MenuScreen extends Activity {  

@Override
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

Button btn1 = (Button) findViewById (R.id.test);
Button btn2 = (Button) findViewById (R.id.test1);
Button btn3 = (Button) findViewById (R.id.test2);
Button btn4 = (Button) findViewById (R.id.verlaat_app);

btn1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Log.d("DEBUG", "test");
        Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
        startActivity (intent);
    }
});


btn2.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Log.d("DEBUG", "test1");
        Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
        startActivity (intent);
    }
});

btn3.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Log.d("DEBUG", "test2");
        Intent intent = new Intent(MenuScreen.this, FotoMaker.class);
        startActivity (intent);
    }
});



btn4.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Log.d("DEBUG", "test3");
        MenuScreen.this.finish();
    }
});
}
}