XML : Can't do a simple data passing with an intent (Android)

It displays the xml in the other activity, i mean, the intent works but my string value isn't as expected.

I only want to get the String in the other activity to fill with a color a figure in a canvas. The canvas work with local variables.

I want to get the F*cking string value of my other activity, i mean, i putted a "valor" on the intent String value, still doesnt work, don't know why.

Any help is fully appreciated, I guess the problem is in the getIntent method, or something like that.

Receiver activity

  package com.example.escom.dbms2;    import android.content.Context;  import android.content.Intent;      import android.graphics.Canvas;      import android.graphics.Color;      import android.graphics.Paint;      import android.graphics.Path;      import android.graphics.Rect;      import android.support.v7.app.AppCompatActivity;      import android.os.Bundle;      import android.view.Menu;      import android.view.MenuItem;      import android.view.View;        public class FiguraActvity extends AppCompatActivity {    public final static String KEYFIG = "colorID";    @Override  protected void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);        Bundle bundle = getIntent().getExtras();      String cID = (String) bundle.get(KEYFIG);        Figura currentFig = new Figura(this);          currentFig.setCurrentColorID(cID);        if (cID =="valor") {          setContentView(currentFig);      }        setContentView(R.layout.activity_figura_actvity);    }        public class Figura extends View {        String currentColorID;        public Figura(Context c) {          super(c);            }        protected void onDraw(Canvas canvas) {            super.onDraw(canvas);                  Rect rectangulo = new Rect();          rectangulo.set(0,0,canvas.getWidth()/2,canvas.getHeight()/2);            Paint currentcolor = new Paint();            if (currentColorID =="1") {              currentcolor.setColor(Color.WHITE);          }            else if (currentColorID =="2"){              currentcolor.setColor(Color.BLUE);          }            else if (currentColorID =="3"){              currentcolor.setColor(Color.RED);          }            else  {              currentcolor.setColor(Color.YELLOW);          }            currentcolor.setStyle(Paint.Style.FILL);            canvas.drawRect(rectangulo,currentcolor);              }        public void setCurrentColorID(String ID){            currentColorID=ID;        }      }        }         package com.example.escom.dbms2;          import android.app.Activity;      import android.app.AlertDialog.Builder;      import android.content.Context;      import android.content.Intent;      import android.database.Cursor;      import android.database.sqlite.SQLiteDatabase;      import android.graphics.Bitmap;      import android.graphics.BitmapFactory;      import android.graphics.Canvas;      import android.graphics.Color;      import android.graphics.Paint;      import android.graphics.Path;      import android.os.Bundle;      import android.view.MotionEvent;      import android.view.View;      import android.view.View.OnClickListener;      import android.widget.*;    

Sender Activity, in the if(v==jbnV) is the intent.

      public class DbmsActivity2 extends Activity implements OnClickListener{    public final static String KEYFIG = "colorID";  EditText        jetI, jetN;  Button          jbnA, jbnB, jbnC, jbnV, jbnL, jbnI, jbnF;  SQLiteDatabase  db;  String currentColorID;  String currentColorName;  @Override  public void onCreate(Bundle b){      super.onCreate(b);      setContentView(R.layout.activity_dbms2);      jetI=(EditText)findViewById(R.id.xetI);      jetN=(EditText)findViewById(R.id.xetN);        jbnA=(Button)findViewById(R.id.xbnA);   jbnA.setOnClickListener(this);      jbnB=(Button)findViewById(R.id.xbnB);   jbnB.setOnClickListener(this);      jbnC=(Button)findViewById(R.id.xbnC);   jbnC.setOnClickListener(this);      jbnV=(Button)findViewById(R.id.xbnV);   jbnV.setOnClickListener(this);      jbnL=(Button)findViewById(R.id.xbnL);   jbnL.setOnClickListener(this);      jbnI=(Button)findViewById(R.id.xbnI);   jbnI.setOnClickListener(this);      jbnF=(Button)findViewById(R.id.xbnF);   jbnF.setOnClickListener(this);            db=openOrCreateDatabase("DBColores", Context.MODE_PRIVATE, null);        db.execSQL("CREATE TABLE IF NOT EXISTS colores (ID VARCHAR, nombre VARCHAR);");        db.execSQL("DELETE FROM colores WHERE ID='" + "1" + "'");      db.execSQL("DELETE FROM colores WHERE ID='" + "2" + "'");      db.execSQL("DELETE FROM colores WHERE ID='" + "3" + "'");      db.execSQL("DELETE FROM colores WHERE ID='" + "4" + "'");      db.execSQL("INSERT INTO colores VALUES('" + "1" + "','" + "BLACK" + "');");      db.execSQL("INSERT INTO colores VALUES('" + "2" + "','" + "BLUE" + "');");      db.execSQL("INSERT INTO colores VALUES('" + "3" + "','" + "RED" + "');");      db.execSQL("INSERT INTO colores VALUES('" + "4" + "','" + "YELLOW" + "');");    }  public void onClick(View v){      if(v==jbnA){          if( jetI.getText().toString().trim().length()==0 || jetN.getText().toString().trim().length()==0){              mensaje("Error", "Ingresar todos los datos");              return;          }          db.execSQL("INSERT INTO colores VALUES('" + jetI.getText() + "','" + jetN.getText() + "');");          mensaje("Alta", "Registro agregado");          limpiar();      }      if(v==jbnB){          if(jetI.getText().toString().trim().length()==0){              mensaje("Error", "Ingresar el ID");              return;          }          Cursor c=db.rawQuery("SELECT * FROM colores WHERE ID='" + jetI.getText() + "'", null);          if(c.moveToFirst()) {              db.execSQL("DELETE FROM colores WHERE ID='" + jetI.getText() + "'");              mensaje("Baja", "Registro eliminado");          } else {              mensaje("Error", "ID inválido");          }          limpiar();      }      if(v==jbnC){          if(jetI.getText().toString().trim().length()==0) {              mensaje("Error", "Ingresar el ID");              return;          }          Cursor c=db.rawQuery("SELECT * FROM colores WHERE ID='" + jetI.getText() + "'", null);          if(c.moveToFirst()) {              db.execSQL("UPDATE colores SET nombre='" + jetN.getText()  + "' WHERE ID='" + jetI.getText() + "'");              mensaje("Cambio", "Registro modificado");          } else {              mensaje("Error", "ID inválido");          }          limpiar();      }      if(v==jbnV) {          if(jetI.getText().toString().trim().length()==0) {              mensaje("Error", "Ingresar el ID");              return;          }            Cursor c=db.rawQuery("SELECT * FROM colores WHERE ID='" + jetI.getText() + "'", null);          if(c.moveToFirst()) {               //currentColorID = jetI.getText().toString();              currentColorID = "1";                 Intent i;              i = new Intent(getApplicationContext(), FiguraActvity.class);                  i.putExtra(KEYFIG,"valor");                  startActivity(i);            }          else   {              mensaje("Error", "ID inválido");              limpiar();          }      }      if(v==jbnL)  {          Cursor c=db.rawQuery("SELECT * FROM colores", null);          if(c.getCount()==0){              mensaje("Error", "No hay registros");              return;          }          StringBuffer buffer=new StringBuffer();          while(c.moveToNext())    {              buffer.append("ID: " + c.getString(0)+"\n");              buffer.append("Nombre: " + c.getString(1)+"\n");            }          mensaje("Lista", buffer.toString());      }      if(v==jbnI)  {          mensaje("Examen App Development for Mobile", "ESCOM");      }          if(v==jbnF)  {        startActivity(new Intent(DbmsActivity2.this, LienzoActivity.class));        }    }  public void mensaje(String s,String m)  {      Builder b=new Builder(this);      b.setCancelable(true);      b.setTitle(s);      b.setMessage(m);      b.show();  }  public void limpiar()    {      jetI.setText("");      jetN.setText("");      jetI.requestFocus();  }               }    

No comments:

Post a Comment