ArrayAdapter建议或建议

时间:2013-08-18 05:17:07

标签: android android-arrayadapter gesture prediction

我正在试图弄清楚如何在我的手势上绑定一系列预测。在代码中我想要的是,我希望我的手势笔划预测在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.

1 个答案:

答案 0 :(得分:0)

一旦你有了Predictions而不是传递它,就会根据结果传递create arraylist。

<强>代码:

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);