1
我做了一個程序,當用戶按下圖像按鈕時,他將從圖庫中選擇一個圖像,該圖像將被添加到圖像按鈕中。現在我需要擴展程序,當用戶按下添加按鈕時,圖像按鈕中的圖像將與描述一起存儲在數據庫中(用戶在編輯文本中輸入文本,例如運動)...我已經創建了一個類數據庫等...Android將圖像添加到數據庫
任何人都可以幫助我添加案件'案件R.id.button2'的代碼是什麼時候添加按鈕被點擊嗎?
非常感謝
public class NewPortal extends Activity implements OnClickListener, android.view.View.OnClickListener
{
public static final int REQUEST_CODE =1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.portallayout);
ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton2);
btn1.setOnClickListener(this);
Button btn2 = (Button)findViewById(R.id.button2);
btn2.setOnClickListener(this);
}
public void onClick(View v) {
Toast pieceToast=null;
switch (v.getId()) {
case R.id.imageButton2:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, REQUEST_CODE);
break;
case R.id.button2:
break;
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RESULT_CANCELED) return;
ParcelFileDescriptor fd;
try {
fd = getContentResolver().openFileDescriptor(data.getData(), "r");
} catch (FileNotFoundException e) {
e.printStackTrace();
return;
}
Bitmap bmp = BitmapFactory.decodeFileDescriptor(fd.getFileDescriptor());
ImageButton imgButton = (ImageButton)findViewById(R.id.imageButton2);
imgButton.setImageBitmap(bmp);
}
}
我應該那樣做嗎?圖像已經存儲在內部...當我按下添加按鈕時,它應該存儲到數據庫,以便我可以在需要時檢索它。 – user3074215