2012-05-28 36 views
-2

我在android系統中創建一個按鈕checkdata當我點擊它裏面寫的,它亙古不變的做任何事......什麼是代碼shoulb情況statmenet

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); 
} 

}

有何應該寫在這種情況下的聲明,以便我可以看到保存在數據庫中的圖像

+0

你寫按鈕OnclickListner.check它。 – kyogs

回答

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) ... 
     } 
    } 
} 

嘗試像上面的代碼。

+0

這段代碼看起來很熟悉...... http://stackoverflow.com/q/10780305/1267661 – Sam

相關問題