0

我试图弄清楚如何在我的手势上绑定选择的预测。我在代码中想要的是,我希望我的手势笔画预测绑定在 ArrayAdapter 上,它显示为布局选择。

不幸的是,我在这段代码上找到了一种不起作用的方法。提前谢谢你们!

TextView edittext = (TextView) findViewById(R.id.editText1);
ArrayList<Prediction> predictions = gLibrary.recognize(gesture);

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, predictions);
edittext.setAdapter(adapter);

这是我正在使用的当前代码

@Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    AutoCompleteTextView edittext = (AutoCompleteTextView) findViewById(R.id.myautocomplete);        
    ArrayList<Prediction> predictions = gLibrary.recognize(gesture); 

    ArrayList<String> al = new ArrayList<String>();

    if (predictions.size() > 0 && predictions.get(0).score > 1.0) {
        String result = predictions.get(0).name;
        edittext.setText(edittext.getText().toString() + result);
        }
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, al);
    edittext.setAdapter(adapter);
}
}

一旦用户做出手势,我想要适配器布局上的预测对象列表的结果,这样他/她就可以选择适当的字符。如果您有建议,此代码只能识别字符而不是单词。请。这样做..谢谢大家!

goal:
once the user draw a gesture, register the stroke.
once the stroke already captured, use the gesture prediction library and bind it in adapter.
once the user input his gesture for example S, he/she may have the option to select the correct gesture character on selection that was bind on adapter.
4

1 回答 1

0

一旦你有了预测而不是传递它,就根据结果创建数组列表。

代码:

ArrayList<String> al= new Arraylist<String>();

 if (predictions.size() > 0 && predictions.get(0).score > 1.0) {
        String result = predictions.get(0).name;

        if ("A".equalsIgnoreCase(result)) {
                    al.add(result);
            Toast.makeText(this, "A", Toast.LENGTH_SHORT).show();
}

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, al);
edittext.setAdapter(adapter);
于 2013-08-18T05:32:06.483 回答