【问题标题】:ArrayAdapter Advice or SuggestionsArrayAdapter 建议或建议
【发布时间】:2013-08-18 05:17:07
【问题描述】:

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

【问题讨论】:

    标签: android android-arrayadapter gesture prediction


    【解决方案1】:

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

    代码:

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

    【讨论】:

    • 嗨 srikanth,感谢您的回复。但目前,我想要的是那个。一旦手势已经预测了 textview 中的手势笔划,适配器将根据预测对象上的预测传递快速建议。我已经测试并安排了你的代码.. 坦克
    • 代码不能通过根据结果创建数组列表
    • 我做了这样的事情...使用 GestureBuilder 我曾经创建所有可能的手势(对于 S 不同的可能组合)并根据结果进行验证。我不确定你将如何绑定但是即使你绑定了预测,你将如何比较它???
    • 我已经解决了这个问题。问题出在这一行。 ` ArrayList al = new ArrayList();` ArrayList&lt;String&gt; al = new ArrayList&lt;String&gt;(predictions); 唯一的问题是它返回类似The constructor ArrayList&lt;String&gt;(ArrayList&lt;Prediction&gt;) is undefined 2 quick fixes available Remove the argument to match 'ArrayList&lt;String&gt;()' and Change type of predictions to 'int'
    • nice :) 正如我所说,我尝试了我在评论中提到的东西 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 2010-10-11
    相关资源
    最近更新 更多