FileInputStreamを使用してlistView内にimageViewを作成したい場合は、File OutputStreamを使用して自分のカメラ画像をsdCardに出力します。ここで私のコードノートは、エミュレータで使用するために私のコンピュータのパスを変更したものです。ここfileinputstreamを使用してlistView内のimageviewにデータを入力する方法
public class CameraAPI extends Activity implements SurfaceHolder.Callback{
public Camera camera;
MediaRecorder mediaRecorder;
CBDataBaseHelper RH;
TextView RecipeID;
public void onCreate (Bundle savedInstanceState){
boolean diditwork;
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
RecipeID = (TextView)findViewById(R.id.Rid2);
String RowID;
Bundle extras = getIntent().getExtras();
RowID = extras.getString("SELECTED2");
RecipeID.setText(RowID);
SurfaceView surface = (SurfaceView)findViewById(R.id.acccam);
SurfaceHolder holder = surface.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}catch(Exception e){
diditwork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("darn");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}}
public void takePhoto(View view){
//String ID = RecipeID.getText().toString();
//Long LID = Long.parseLong(ID);
boolean diditwork;
try{
takePicture();
}catch(Exception e){
diditwork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("darn");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}
//String path = "/sdcard/Image.jpg";
//RH.updateRecipe3(LID,path);
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
if (mediaRecorder == null){
try{
camera = camera.open();
camera.setPreviewDisplay(holder);
camera.startPreview();
}catch (IOException e){
Log.d("CAMERA", e.getMessage());
}
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
camera.stopPreview();
camera.release();
}
public void takePicture(){
boolean diditwork;
try{
camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}catch(Exception e){
diditwork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("darn");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}
}
ShutterCallback shutterCallback= new ShutterCallback()
{
public void onShutter(){
}
};
PictureCallback rawCallback = new PictureCallback(){
public void onPictureTaken(byte[] data, Camera camera){
}
};
PictureCallback jpegCallback = new PictureCallback(){
public void onPictureTaken(byte[] data, Camera camera){
FileOutputStream outStream = null;
try{
outStream = new FileOutputStream("//STEFAN-PC/Users/stefan/Desktop/Uni Work/Image.jpg");
outStream.write(data);
outStream.close();
}catch(FileNotFoundException e){
Log.d("CAMERA", e.getMessage());
}catch(IOException e){
Log.d("CAMERA",e.getMessage());
}
/*RH = new CBDataBaseHelper(CameraAPI.this);
RH.open();
String ID = RecipeID.getText().toString();
Long RID = Long.parseLong(ID);
RH.updateRecipe3(RID, data);
RH.close();*/
String ID = RecipeID.getText().toString();
Long RID = Long.parseLong(ID);
RH.updateRecipe3(RID, "/sdcard/Image.jpg");
}
};
}
、その後、私のコードは、私がリストビューを移入していた場所にようである、いずれかは私に私はImageViewのに画像をロードすることができる方法についてのポインタやレイアウトのコードスニペットを与えることができますか?リストビューでImageViewのを表示したい場合は
public class CBFilter extends ListActivity {
ListView RecipeNames;
Cursor cursor;
SimpleCursorAdapter adapter;
CBDataBaseHelper data;
SQLiteDatabase data2;
TextView RecipeText, RowId;
String[] from = { CBDataBaseHelper.KEY_NAME};
int[] to = { R.id.row};
ImageView image;
byte[] dataImage;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
boolean diditwork;
try{
//java.io.FileInputStream in = openFileInput("myImage.jpg");
RecipeNames = (ListView) findViewById(android.R.id.list);
RecipeNames.setTextFilterEnabled(true);
RecipeText = (TextView) findViewById(R.id.recipeText);
adapter = new SimpleCursorAdapter (this, 0, cursor, null, null);
image = (ImageView) findViewById(R.id.RecipeImage);
data = new CBDataBaseHelper(this);
data.open();
cursor = data.query();
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
RecipeNames.setAdapter(adapter);
adapter.notifyDataSetChanged();
}catch(Exception e){
diditwork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("darn");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}}
public void CreateNew(View view){
Intent myIntent = new Intent(this, CBCreate.class);
startActivity(myIntent);
}
@Override
public void onListItemClick(ListView parent, View v, int position, long id) {
super.onListItemClick(parent, v, position, id);
Intent intent1 = new Intent(this, CBCreate.class);
long rowId = cursor.getLong(cursor.getColumnIndex(CBDataBaseHelper.KEY_ROWID));
String s = String.valueOf(rowId);
intent1.putExtra("SELECTED", s);
startActivity(intent1);
}
}
感謝ステファン
これは配列アダプタです...このメソッドはカーソルアダプタでも機能しますか? – aspiringCoder
@StefanReaney SQLite dbを読んでレシピのリストを取得し、上記のようなカスタムアダプタを定義することができます。そうでなければ、少し異なったカスタムCursorAdapterを定義できます。newViewとbindViewをオーバーライドする必要があります。 ://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/) –