当前位置: 首页 > 知识库问答 >
问题:

在TEXTVIEW中添加分数

龙佐
2023-03-14

我的应用程序中有一个autocompletetextview、一个textview和一个按钮。单击该按钮时,它将在数据库中搜索与TextView中的单词相等的单词。

flow:•Word from autocompletetextview(通过单击imagebuttons输入)>Search Word(使用按钮)条件:•如果Word在数据库中,textview将显示相应的分数(也在dbase中),则autocompletetextview应清除该文本(生成另一个Word)。

问题:1。我如何添加第一个分数,它已经在textview和下一个单词的分数?2.如何禁用AutoCompleteTextView中的“EditText”效果?我需要这样做来“优先”只通过imagebuttons进行输入(我的意思是,无论何时您有一个autocompletetextview,它就像您有一个编辑文本一样)。

如有任何建议,将不胜感激。我不知道怎么做所以我问这个问题。我是android编程的新手。我希望你能理解我的问题和我的语法:)

下面是我使用的代码:mainactivity.java

DBAdapter dbHelper;
TextView score;
protected static final String TAG = null;
String generatedString = " ";
AutoCompleteTextView text;
TextView timer;
ImageButton searchWord;
ImageButton image1, image2, image3, image4, image5, image6, image7, image8,
image9, image10, image11, image12, image13, image14, image15, image16;
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);
searchWord = (ImageButton) findViewById(R.id.searchWord);
image1 = (ImageButton) findViewById(R.id.Button1);

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 int[] myPics = { images here };


int rando = (int)(Math.random()* 5);
image1.setImageResource(myPics[rando]);
image1.setId(myPics[rando]);


OnClickListener myCommoClickListner = new OnClickListener(){

@Override
public void onClick(View arg0) {
// start timer  when 1 of 16 imagebutton is click ( display letters = image in imagebutton
};



image1.setOnClickListener(myCommoClickListner);
}

@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi") public class MyCountDownTimer extends CountDownTimer{
public MyCountDownTimer(long millisInFuture, long countDownInterval){
super(millisInFuture, countDownInterval);
}

@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi") @Override
public void onTick(long millisUntilFinished) {
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!");
}
}

//Search
public void viewWord(View view)
{
score = (TextView)findViewById(R.id.yourScore);
String s1= search.getText().toString();
String s2= dbHelper.getData(s1);
score.setText(s2);
}
}

这是我的dbadapter中搜索代码时的代码:公共字符串getData(String word){SQLiteDatabase db=helper.getWritableDatabase();String[]columns={dbhelper.word,dbhelper.score};Cursor Cursor=db.query(dbhelper.table_name,columns,dbhelper.word+“=‘”+word+“’”,null,null,null,null,null,null);StringBuffer buffer=new StringBuffer();while(Cursor.MoveTonext()){int index1=Cursor.getColumnIndex(dbhelper.word);int index2==Cursor.GetString(index2);buffer.Append(score+“\n”);}返回buffer.ToString();}

共有1个答案

蒋泰
2023-03-14

你的问题有点不清楚,但我会试着根据我的解释来回答:

  1. 如何添加第一个分数,该分数已经在textview中,以及下一个单词的分数?

我假设你想把第一个分数和下一个分数相加?

public String getData(String word)
    {
    SQLiteDatabase db = helper.getWritableDatabase();
    String[] columns={DBHelper.WORD, DBHelper.SCORE};
    Cursor cursor=db.query(DBHelper.TABLE_NAME, columns, DBHelper.WORD+ "= '"+word+"'", null, null, null, null);
    StringBuffer buffer = new StringBuffer();
    cursor.moveToFirst(); 
    // Given that you are only finding one instance, while is not necessary and in fact may not do what you want. It will return the LAST instance of your query value
        int index1 =cursor.getColumnIndex(DBHelper.WORD);
        int index2 =cursor.getColumnIndex(DBHelper.SCORE);
        String words =cursor.getString(index1);
        String score =cursor.getString(index2);

    cursor=db.query(DBHelper.TABLE_NAME, columns, "*", null, null, null, null); // "*" should be the wildcard for SQL

        cursor.moveToNext();
        int indexSecond1 =cursor.getColumnIndex(DBHelper.WORD);
        int indexSecond2 =cursor.getColumnIndex(DBHelper.SCORE);
        // Do something with the data


        buffer.append(score +"\n");

    return buffer.toString();
}
 类似资料:
  • 问题内容: 我试图在代码中添加到xml定义的布局中。我有一个xml工作表,其中定义了很多。但是我必须在代码中添加一些视图,因此在中创建一个: 在这种布局中,我想添加我的: 但是我只收到以下错误消息: 我该怎么做? 问题答案: 尝试使用 还请确保你正在创建的布局参数是LinearLayout.LayoutParams …

  • 问题内容: 我有一个问题,我不知道如何将textview添加到gridlayout。我有一个xml: 并希望动态地执行此xml代码。我怎样才能做到这一点?我知道如何创建textview,但我不知道如何添加到gridlayout … 问题答案: 您不能将代码粘贴到其中,并且需要对其进行测试和更改以使其适合(它不仅会起作用)。但这应该给您大致的想法。

  • 问题内容: 我正在尝试在python中添加两个分数 如果输入1/4 + 1/4,我期望得到1/2结果 我用加法建立了一个分数类 但是我得到的输出是2,4,实际上是1/2,只是没有简化。我该如何解决这个问题? 问题答案: 简化分数的一般方法是找到分子和分母的最大公约数,然后将两者除以

  • 问题内容: 为什么以下代码不起作用?它可以在Toast中工作,但不能在TextView中工作。当我运行程序时,boldName不会显示为粗体,但是当我将其设置为Toast时,它会显示为粗体。有人还有其他解决方案吗? 问题答案: 老实说,我不确定为什么TextViews完全按照它们的方式工作,您可以在执行操作时将其全部设置为粗体,但前提是它们的整个TextView都为粗体,但是如果其中一部分是粗体的

  • 问题内容: 我从第一页的API解析数据并将其添加到中,现在页面可以是多个,比如说100,我也可以从API获取页面总数。但是我将如何在tableView中为每个页面实现它并在滚动时显示指示器。看看我的代码 问题答案: 有很多方法可以实现这一点,例如以下方法: 首先,您需要创建一个在Delegates和中加载的全局变量。 现在,在您的api调用上,您需要在全局数组中添加That记录。 在最后一个单元格

  • 我尝试在我的GridLayout RecyclerView中添加水平分隔线。但出于某种原因,分割线没有出现。 作为替代方法,我使用具有 2 个参数的 addItemDecoration 方法,其中第二个参数是索引,之后添加 ItemDecoration。 它强制关闭,但有以下例外: 这个尺寸意味着什么?为什么是零? 可能是因为我在活动而不是片段中使用此回收器视图吗? P、 美国:适配器没有问题;它