私は単語ゲームを書こうとしています。そのため、ある時点で、仮想キーボードで押されたキーを取得する必要があります。そして、この手紙を textView に書き込む必要があります。EditText は使用しないでください。私はリスナーなどに完全に行き詰まっています。
どんな助けでも大歓迎です。
public class Oyun extends Activity implements OnKeyboardActionListener
{
@Override
public void onCreate(Bundle savedInstanceState)
{
overridePendingTransition(R.anim.push_left_in,R.anim.push_up_out);
super.onCreate(savedInstanceState);
setContentView(R.layout.oyun);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
in = this.getResources().openRawResource(R.raw.source);
reader = new BufferedReader(new InputStreamReader(in));
sayac = (TextView)findViewById(R.id.counterDown);
soru = (TextView)findViewById(R.id.Soru);
answerButton = (ImageButton)findViewById(R.id.CevapButon);
harfAlButton = (ImageButton)findViewById(R.id.HarfAlButon);
leyat = (LinearLayout)findViewById(R.id.leyat);
final MyCounter timer = new MyCounter(240000, 1000);
timer.start();
try
{
bringQuestion(reader, in);
}
catch (IOException e)
{
e.printStackTrace();
}
harfAlButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
harfAl();
if(alinanHarfSayisi == uzunluk)
{
alinanHarfSayisi = 0;
try
{
bringQuestion(reader, in);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
});
answerButton.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
letter[5].setVisibility(View.INVISIBLE);
if(keyCode==KeyEvent.KEYCODE_A)
{
letter[1].setText("A");
}
return false;
}
});
answerButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
/*try
{
bringQuestion(reader, in);
}
catch (IOException e)
{
e.printStackTrace();
}*/
}
});
}
public int harfAl()
{
alinanHarfSayisi++;
rand = rastgeleHarf.nextInt(uzunluk);
while(letter[rand].getText() != "")
{
rand = rastgeleHarf.nextInt(uzunluk);
}
desired = cevap.charAt(rand);
letter[rand].setText(""+ desired);
return alinanHarfSayisi;
}
public class MyCounter extends CountDownTimer
{
public MyCounter(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished)
{
long minutes = millisUntilFinished/60000;
long rSeconds = millisUntilFinished%60000;
long seconds = rSeconds/1000;
if(seconds>=10)
{
sayac.setText(minutes + ":" + seconds);
}
else
{
sayac.setText(minutes + ":0" + seconds);
}
}
@Override
public void onFinish()
{
}
}
public void bringQuestion(BufferedReader rea, InputStream inputS) throws IOException
{
if (inputS!=null)
{
if ((line = rea.readLine()) != null)
{
soru.setText(line);
cevap = rea.readLine();
}
}
//is.close();
for(int i = 0; i<uzunluk; i++)
{
letter[i].setVisibility(View.GONE);
}
uzunluk = cevap.length();
letter = new TextView[uzunluk];
for(int i = 0; i<uzunluk; i++)
{
letter[i]=new TextView(this);
letter[i].setBackgroundResource(R.drawable.shape);
letter[i].setGravity(17);
letter[i].setTextColor(Color.BLACK);
letter[i].setTextSize(20);
letter[i].setTypeface(Typeface.SERIF, Typeface.BOLD);
letter[i].setText("");
this.leyat.addView(letter[i]);
}
}
@Override
public void onKey(int primaryCode, int[] keyCodes)
{
if(primaryCode==KeyEvent.KEYCODE_A)
{
letter[1].setText("B");
}
}
@Override
public void onPress(int primaryCode)
{
if(primaryCode==KeyEvent.KEYCODE_A)
{
letter[1].setText("C");
}
}
@Override
public void onRelease(int primaryCode) {
// TODO Auto-generated method stub
}
@Override
public void onText(CharSequence text) {
// TODO Auto-generated method stub
}
@Override
public void swipeDown() {
// TODO Auto-generated method stub
}
@Override
public void swipeLeft() {
// TODO Auto-generated method stub
}
@Override
public void swipeRight() {
// TODO Auto-generated method stub
}
@Override
public void swipeUp() {
// TODO Auto-generated method stub
}
}