Android: постоянно нажимайте от одной до шести кнопок [одну за другой], чтобы объединить разные результаты
Я решил поработать над приложением для Android, которое использует технологию, очень похожую на приложение, которое я видел раньше. Я хотел связать несколько нажатий кнопок, чтобы приравнять к разным текстовым результатам.
Шесть точек - приложение Брайля (фактическое применение для использования)
Это собственное приложение Брайля, которое я делаю, имеет 6 разных кнопок, которые я хотел бы, чтобы каждая уникальная комбинация приносила мне разные буквы. Например: я хотел бы нажать кнопку 1, чтобы просто принести мне букву «А». Затем нажатие кнопки 1 и кнопки 2 непрерывно приносит мне букву «С». Я хочу, чтобы каждая комбинация этих 6 кнопок приносила мне отдельное письмо.
Может кто-то, кто является опытным в Java, пожалуйста, объясните, как это делается? Как я могу натянуть несколько нажатий кнопок, чтобы привести меня к другому результату? Спасибо за помощь.
Мой код на Java:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.keyboard);
Window window = this.getWindow();
window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
// Init GUI
txtMessage = (EditText) findViewById(R.id.txtMesssage);
Button buttonOne = (Button) findViewById(R.id.block1);
Button buttonTwo = (Button) findViewById(R.id.block2);
Button buttonThree = (Button) findViewById(R.id.block3);
Button buttonFour = (Button) findViewById(R.id.block4);
Button buttonFive = (Button) findViewById(R.id.block5);
Button buttonSix = (Button) findViewById(R.id.block6);
// Attached Click Listener
btnSend.setOnClickListener(this);
buttonOne.setOnClickListener(this);
buttonTwo.setOnClickListener(this);
buttonThree.setOnClickListener(this);
buttonFour.setOnClickListener(this);
buttonFive.setOnClickListener(this);
buttonSix.setOnClickListener(this);
}
@Override
public void onClick(View v) {
}
switch (v.getId()) {
case R.id.block1:
break;
case R.id.block2:
break;
case R.id.block3:
break;
case R.id.block4:
break;
case R.id.block5:
break;
case R.id.block6:
break;
}
txtMessage.setText();
}
//functions below.
.... ....
... ...
.. ..
. O .
.. ..
... ...
.... ....
На моем XML-макетеkeyboard.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/lightgrey">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/txtMesssage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Message"
android:textColor="@color/darkbrown" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<Button
android:id="@+id/block1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:layout_weight="1.0"
android:text="Button one" />
<Button
android:id="@+id/block2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@color/blue"
android:text="Button two" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<Button
android:id="@+id/block3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@color/bg_gradient_end"
android:text="Button three" />
<Button
android:id="@+id/block4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@color/darkgrey"
android:text="Button four" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<Button
android:id="@+id/block5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@color/lightgrey"
android:text="Button five" />
<Button
android:id="@+id/block6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:background="@color/bg_gradient_start"
android:text="Button six" />
</LinearLayout>
Код, который я сделал до сих пор, не работает так, как я хотел, поэтому я оставляюswitch
Заявление пока пустое. Пожалуйста, исправьте меня в моих кодах или помогите мне с этим. Спасибо
Мой код таймера:
Timer processTimer = new Timer();
processTimer.schedule(new TimerTask() {
public void run() {
processInput();
}
private void processInput() {
// TODO Auto-generated method stub
map.put(getString(R.id.block1), "A");
map.put(getString(R.id.block1) + getString(R.id.block2), "C");
}
}, 500); // Delay before processing.
processTimer.cancel();
processTimer.schedule(new TimerTask() {
public void run() {
processInput();
}
private void processInput() {
// TODO Auto-generated method stub
map.get(R.id.block1);
map.get(R.id.block1+R.id.block2);
//this.close();
}
}, 500);
Это правильно?