应该在case语句中编写什么代码

时间:2012-05-28 06:51:38

标签: android

我在Android上创建了一个按钮checkdata,当我点击它时,它什么也没做......

switch(v.getId()){

        case R.id.Button01add:
            showDialog(DIALOG_ID);
            break;

        case R.id.Button01check:
             break;
        }

当我点击添加它时显示一些对话框弹出,就像我要显示当我点击检查按钮时保存在数据库中的图像 这是我的checkdata.java

public class CheckData extends ListActivity  {     
    TextView selection;
    DataManipulator dm;
    private DataManipulator DbHelper;
private Object testFruit;
    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.check);
    dm = new DataManipulator(this);

    LinearLayout layout = new LinearLayout(this);
    ImageView image = new ImageView(this);
    DbHelper = new DataManipulator(this);

    DbHelper.open();
    DbHelper.createFruitEntry((Fruit) testFruit);
    DbHelper.close();

    testFruit = null;

    DbHelper.open();
    testFruit = DbHelper.getFirstFruitFromDB();
    DbHelper.close();

    image.setImageBitmap(((Fruit) testFruit).getBitmap());

    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
                                    LinearLayout.LayoutParams.WRAP_CONTENT,
                                    LinearLayout.LayoutParams.WRAP_CONTENT);

    setContentView(layout);
    addContentView(image, params);
}

}

在这个案例陈述中应该写什么,以便我可以看到保存在数据库中的图像

1 个答案:

答案 0 :(得分:0)

public class TestActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

  Button aboutButton =(Button)findViewById(R.id.about_content);
        aboutButton.setOnClickListener(this);
    }
public void onClick(View v) {
        switch (v.getId()) {
        case R.id.about_content:
        break;
        // More buttons go here (if any) ...
        }
    }
}

尝试上面的代码。