所以在我的应用程序中我有这个4x4图像按钮。我没有任何Android编程经验,因为这是我的第一个应用程序。如图所示,我正在形成一个单词“BIT”(以texview显示)。我的问题是如何点击这些图像按钮来形成单词而不抬起手指?任何建议将受到高度赞赏。我很乐意,如果你也帮我提供代码。
继承我正在使用的代码:
MainActivity.java
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends Activity {
DBAdapter dbHelper;
EditText words, scores, search;
ImageView show_addWord;
TextView score, tv2, tv3;
int x = 0;
int y = 0;
int z = 0;
protected static final String TAG = null;
String generatedString = " ";
AutoCompleteTextView text;
TextView timer;
ImageView searchWord;
ImageView bomb, searchword, lineone;
ImageButton image1, image2, image3, image4, image5, image6, image7, image8,
image9, image10, image11, image12, image13, image14, image15, image16;
ListView wordList;
private CountDownTimer countDownTimer;
private boolean timeHasStarted = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dbHelper =new DBAdapter(this);
search = (EditText) findViewById(R.id.textHere);
words = (EditText) findViewById(R.id.edWord);
scores = (EditText) findViewById(R.id.edScore);
show_addWord = (ImageView) findViewById(R.id.show_addWord);
bomb = (ImageView) findViewById(R.id.bomb);
searchWord = (ImageView) findViewById(R.id.searchWord);
wordList = (ListView) findViewById(R.id.wordList);
image1 = (ImageButton) findViewById(R.id.Button1); ...
image16 = (ImageButton) findViewById(R.id.Button16);
timer = (TextView) this.findViewById(R.id.timer);
timer.setText("00:00:30");
countDownTimer = new MyCountDownTimer(30000,1000);
final AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.textHere);
final ImageButton image1 = (ImageButton) findViewById(R.id.Button1); ..
final ImageButton image16 = (ImageButton) findViewById(R.id.Button16);
final int[] myPics = { R.drawable.a, R.drawable.b, R.drawable.c, ... };
//randomize image
bomb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//new set of tile
}
});
// start countdowntimer, display text in textview according to image
OnClickListener myCommoClickListner = new OnClickListener(){
@Override
public void onClick(View arg0) {
Log.i(TAG,"arg0.getId() = " + arg0.getId());
if(arg0.getId()==R.drawable.a){
Log.i(TAG,"arg0.getId()="+arg0.getId());
generatedString=generatedString+"a"; //[PLACEE RESPACTIVE CHARACTEER HERE]
text.setText(generatedString);
if (!timeHasStarted) {
countDownTimer.start();
timeHasStarted = true;
}
}
};
image1.setOnClickListener(myCommoClickListner);
}
public class MyCountDownTimer extends CountDownTimer{
public MyCountDownTimer(long millisInFuture, long countDownInterval){
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
long millis = millisUntilFinished;
String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
System.out.println(hms);
timer.setText(hms);
}
@Override
public void onFinish() {
timer.setText("Time's Up!");
}
}
// searching word, displaying score on score textview and populating listview via textview data
private int optionTxtView = 0 ;
public void viewWord(View view)
{
score = (TextView)findViewById(R.id.yourScore);
tv2 = (TextView)findViewById(R.id.tv2);
tv3 = (TextView)findViewById(R.id.tv3);
searchWord = (ImageView) findViewById(R.id.searchWord);
wordList = (ListView) findViewById(R.id.wordList);
text = (AutoCompleteTextView) findViewById(R.id.textHere);
wordList = (ListView) findViewById(R.id.wordList);
String s1= search.getText().toString();
String s2= dbHelper.getData(s1);
score.setText(s2);
tv2.setText(s2);
tv3.setText(s2);
/* // Display score on first click in txtview, second click in txtview 2 ...
// NOT WORKING !!!!!!!!
if(optionTxtView == 0){
//display the score on textview1
tv2.setText(s2);
optionTxtView = 1;
}else{
//display the score on textview2
tv3.setText(s2);
optionTxtView = 0;
}
*/
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<String>());
wordList.setAdapter(adapter);
adapter.add(text.getText().toString());
adapter.notifyDataSetChanged();
text.setText("");
}
//adding 2 textview
public void add (){
x = Integer.parseInt(tv2.getText().toString());
y = Integer.parseInt(tv3.getText().toString());
z = x + y;
score.setText(Double.toString(z));
}
}
任何人都可以帮我解决问题吗?
答案 0 :(得分:0)
你想点击图像而不抬起手指?用户这样做,所以告诉他们这样做..(大声说出来)..实际上是在开玩笑。
你所要做的就是调用imagebutton对象并调用一个循环来获取你要输入的字母数,以形成一个单词并在首选的imagebutton上调用.. performClick()
- ()它现在??
所以一个例子..我想拼写 Lab Ley ..我需要点击7 diff图像按钮这样
for(int i = 0; i<7; ++i){ // i++ any way goes
ImageButton.performClick(); // imagebutton is the respective lettered imagebutton you want
}