【问题标题】:how to Toast a certain position on a listview arrayadapter<string>?如何在 listview arrayadapter<string> 上为某个位置敬酒?
【发布时间】:2012-11-29 06:44:03
【问题描述】:
     protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
    {
        // Populate the wordsList with the String values the recognition engine thought it heard
        ArrayList<String> matches = data.getStringArrayListExtra(
                RecognizerIntent.EXTRA_RESULTS);
        wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                matches));


    }



    super.onActivityResult(requestCode, resultCode, data);
}

我正在寻找正确的语法来将此填充列表的第一个位置转换为字符串,以便我可以将其放入 toast 或将其保存到文件中,我是新手,如果我可以在 toast 上显示它剩下的可以搞定,谢谢

Toast.makeText(this,(CharSequence) wordsList.getItemAtPosition(0) , Toast.LENGTH_LONG).show();

【问题讨论】:

    标签: android listview toast


    【解决方案1】:

    很简单:

    String firstResult = matches.get(0);
    Toast.makeText(getContext(), firstResult,
    Toast.LENGTH_SHORT).show();
    

    【讨论】:

    • 感谢我一直在四处寻找几个小时然后我在这里变得简单明了
    • 很高兴我能帮上忙。如果这是您的首选解决方案,请将答案标记为正确。
    【解决方案2】:
    wordList.setOnItemClickListener(new ListView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> a, View v, int pos, long l) {
                try {
                   Toast.makeText(this,"Position is===>>"+pos , Toast.LENGTH_LONG).show();
                }
                catch(Exception e) {
                    System.out.println("Nay, cannot get the selected index");
                }
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2016-11-29
      • 2011-03-10
      • 2014-01-16
      • 2013-08-24
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 2018-05-20
      相关资源
      最近更新 更多