This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

getText() help  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm making a Sudoku app and I'm having trouble with it. When I try to pull the value held in the EditTexts (which represent the squares), I can't seem to get the correct value. I've had this problem before and managed to work around it, but now I just want to deal with problem straight up. Can anyone shed some light on this problem? And on a totally unrelated note, is there a better way to assign the EditText ids? The way I did it seems...inelegant :P



package MadLabs.Suduku;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

public class Suduku extends Activity implements OnClickListener{

private EditText GameButtons [][];

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


//Top Three rows of buttons *****************************************************
this.GameButtons = new EditText [10][10];
this.GameButtons[0][1]=(EditText) findViewById(R.id.EditText01);
this.GameButtons[0][2]=(EditText) findViewById(R.id.EditText02);
this.GameButtons[0][3]=(EditText) findViewById(R.id.EditText03);
this.GameButtons[0][4]=(EditText) findViewById(R.id.EditText04);
this.GameButtons[0][5]=(EditText) findViewById(R.id.EditText05);
this.GameButtons[0][6]=(EditText) findViewById(R.id.EditText06);
this.GameButtons[0][7]=(EditText) findViewById(R.id.EditText07);
this.GameButtons[0][8]=(EditText) findViewById(R.id.EditText08);
this.GameButtons[0][9]=(EditText) findViewById(R.id.EditText09);

this.GameButtons[1][1]=(EditText) findViewById(R.id.EditText11);
this.GameButtons[1][2]=(EditText) findViewById(R.id.EditText12);
this.GameButtons[1][3]=(EditText) findViewById(R.id.EditText13);
this.GameButtons[1][4]=(EditText) findViewById(R.id.EditText14);
this.GameButtons[1][5]=(EditText) findViewById(R.id.EditText15);
this.GameButtons[1][6]=(EditText) findViewById(R.id.EditText16);
this.GameButtons[1][7]=(EditText) findViewById(R.id.EditText17);
this.GameButtons[1][8]=(EditText) findViewById(R.id.EditText18);
this.GameButtons[1][9]=(EditText) findViewById(R.id.EditText19);

this.GameButtons[2][1]=(EditText) findViewById(R.id.EditText21);
this.GameButtons[2][2]=(EditText) findViewById(R.id.EditText22);
this.GameButtons[2][3]=(EditText) findViewById(R.id.EditText23);
this.GameButtons[2][4]=(EditText) findViewById(R.id.EditText24);
this.GameButtons[2][5]=(EditText) findViewById(R.id.EditText25);
this.GameButtons[2][6]=(EditText) findViewById(R.id.EditText26);
this.GameButtons[2][7]=(EditText) findViewById(R.id.EditText27);
this.GameButtons[2][8]=(EditText) findViewById(R.id.EditText28);
this.GameButtons[2][9]=(EditText) findViewById(R.id.EditText29);

//Middle Three Rows of Buttons ******************************************
this.GameButtons[3][1]=(EditText) findViewById(R.id.EditText31);
this.GameButtons[3][2]=(EditText) findViewById(R.id.EditText32);
this.GameButtons[3][3]=(EditText) findViewById(R.id.EditText33);
this.GameButtons[3][4]=(EditText) findViewById(R.id.EditText34);
this.GameButtons[3][5]=(EditText) findViewById(R.id.EditText35);
this.GameButtons[3][6]=(EditText) findViewById(R.id.EditText36);
this.GameButtons[3][7]=(EditText) findViewById(R.id.EditText37);
this.GameButtons[3][8]=(EditText) findViewById(R.id.EditText38);
this.GameButtons[3][9]=(EditText) findViewById(R.id.EditText39);

this.GameButtons[4][1]=(EditText) findViewById(R.id.EditText41);
this.GameButtons[4][2]=(EditText) findViewById(R.id.EditText42);
this.GameButtons[4][3]=(EditText) findViewById(R.id.EditText43);
this.GameButtons[4][4]=(EditText) findViewById(R.id.EditText44);
this.GameButtons[4][5]=(EditText) findViewById(R.id.EditText45);
this.GameButtons[4][6]=(EditText) findViewById(R.id.EditText46);
this.GameButtons[4][7]=(EditText) findViewById(R.id.EditText47);
this.GameButtons[4][8]=(EditText) findViewById(R.id.EditText48);
this.GameButtons[4][9]=(EditText) findViewById(R.id.EditText49);

this.GameButtons[5][1]=(EditText) findViewById(R.id.EditText51);
this.GameButtons[5][2]=(EditText) findViewById(R.id.EditText52);
this.GameButtons[5][3]=(EditText) findViewById(R.id.EditText53);
this.GameButtons[5][4]=(EditText) findViewById(R.id.EditText54);
this.GameButtons[5][5]=(EditText) findViewById(R.id.EditText55);
this.GameButtons[5][6]=(EditText) findViewById(R.id.EditText56);
this.GameButtons[5][7]=(EditText) findViewById(R.id.EditText57);
this.GameButtons[5][8]=(EditText) findViewById(R.id.EditText58);
this.GameButtons[5][9]=(EditText) findViewById(R.id.EditText59);

//Bottom Three Rows of Buttons*******************************************************
this.GameButtons[6][1]=(EditText) findViewById(R.id.EditText61);
this.GameButtons[6][2]=(EditText) findViewById(R.id.EditText62);
this.GameButtons[6][3]=(EditText) findViewById(R.id.EditText63);
this.GameButtons[6][4]=(EditText) findViewById(R.id.EditText64);
this.GameButtons[6][5]=(EditText) findViewById(R.id.EditText65);
this.GameButtons[6][6]=(EditText) findViewById(R.id.EditText66);
this.GameButtons[6][7]=(EditText) findViewById(R.id.EditText67);
this.GameButtons[6][8]=(EditText) findViewById(R.id.EditText68);
this.GameButtons[6][9]=(EditText) findViewById(R.id.EditText69);

this.GameButtons[7][1]=(EditText) findViewById(R.id.EditText71);
this.GameButtons[7][2]=(EditText) findViewById(R.id.EditText72);
this.GameButtons[7][3]=(EditText) findViewById(R.id.EditText73);
this.GameButtons[7][4]=(EditText) findViewById(R.id.EditText74);
this.GameButtons[7][5]=(EditText) findViewById(R.id.EditText75);
this.GameButtons[7][6]=(EditText) findViewById(R.id.EditText76);
this.GameButtons[7][7]=(EditText) findViewById(R.id.EditText77);
this.GameButtons[7][8]=(EditText) findViewById(R.id.EditText78);
this.GameButtons[7][9]=(EditText) findViewById(R.id.EditText79);

this.GameButtons[8][1]=(EditText) findViewById(R.id.EditText81);
this.GameButtons[8][2]=(EditText) findViewById(R.id.EditText82);
this.GameButtons[8][3]=(EditText) findViewById(R.id.EditText83);
this.GameButtons[8][4]=(EditText) findViewById(R.id.EditText84);
this.GameButtons[8][5]=(EditText) findViewById(R.id.EditText85);
this.GameButtons[8][6]=(EditText) findViewById(R.id.EditText86);
this.GameButtons[8][7]=(EditText) findViewById(R.id.EditText87);
this.GameButtons[8][8]=(EditText) findViewById(R.id.EditText88);
this.GameButtons[8][9]=(EditText) findViewById(R.id.EditText89);


for(int x=0; x<=8;x++){
for(int y=1; y<=9;y++){
this.GameButtons[x][y].setOnClickListener(this);
}
}

}

@Override
public void onClick(View v) {
winCheck();
}

public void winCheck(){ //*****************************
Editable checkMe=GameButtons[0][2].getText(); //This is where I'm stuck
String copy=checkMe.toString(); //******************************
if(copy == "1")
GameButtons[1][2].setText("W");
else

GameButtons[1][2].setText("1");

Editable temp=GameButtons[1][2].getText();
copy = temp.toString();

if(copy == "")
GameButtons[2][2].setText("W");

else
GameButtons[2][2].setText("1");
}

}
 
Ranch Hand
Posts: 136
Android Chrome Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Just cast your view object to Button.




Thanks
Pratik Goswami


 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!