我遇到了无法解决的问题...
问题是当我执行默认代码时它只工作一次。如果我再按一次按钮,它会正确显示第二个按钮信息,但第一个按钮信息为空。任何想法?
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.save:
if (et.getText() !=null && thumbnail != null){
TableRow tr = new TableRow(this);
ImageView view = new ImageView(this);
TextView view2 = new TextView(this);
Button view3 = new Button(this);
view3.setOnClickListener(this);
titulo = new String[500];
mensaje = new String[500];
fotos = new Bitmap[500];
view3.setId(i);
view.setImageBitmap(thumbnail);
view.setPadding(1, 5, 0, 0);
view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
Calendar c = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
titulo[i]=""+et.getText();
mensaje[i]=""+et1.getText();
fotos[i]=thumbnail;
view2.setText(titulo[i] + " "+view3.getId()+" "+ i+" "+ dateFormat.format(c.getTime()) );
view2.setGravity(Gravity.CENTER_HORIZONTAL);
view2.setGravity(Gravity.CENTER_VERTICAL);
i++;
view3.setGravity(Gravity.RIGHT);
view3.setGravity(Gravity.CENTER_VERTICAL);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
tr.addView(view, metrics.widthPixels/3, 150);
tr.addView(view2, metrics.widthPixels/2, 100);
tr.addView(view3, metrics.widthPixels/6, 20);
tl.addView (tr, 0);
final Toast toastMensaje = Toast.makeText(getApplicationContext(),
"Tu entrada se cargó correctamente", Toast.LENGTH_LONG);
toastMensaje.setGravity(Gravity.CENTER, 0, 0);
toastMensaje.show();
et.setText("");
et1.setText("");
i1.setVisibility(View.GONE);
}
else{
final Toast toastMensaje = Toast.makeText(getApplicationContext(),
"Tienes que añadir un título y una foto", Toast.LENGTH_LONG);
toastMensaje.setGravity(Gravity.CENTER, 0, 0);
toastMensaje.show();
}
break;
case R.id.photo:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
break;
case R.id.gallery:
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, TFRequestCodes);
break;
default:
Toast toastMensaje = Toast.makeText(getApplicationContext(),
titulo[arg0.getId()], Toast.LENGTH_LONG);
toastMensaje.setGravity(Gravity.CENTER, 0, 0);
toastMensaje.show();
/*
Intent i = new Intent(Second.this, Display.class);
i.putExtra("titulo", titulo[index]);
i.putExtra("mensaje", mensaje[index]);
startActivity(i);*/
break;
}
}