【问题标题】:How do I get the value of the item selected in ListView?如何获取 ListView 中所选项目的值?
【发布时间】:2010-06-03 01:44:09
【问题描述】:

我以为我可以使用positionint,但是当我单击列表视图中的项目时,没有任何反应。请帮忙!

ListView d = (ListView) findViewById(R.id.apo); 
ArrayAdapter adapt = ArrayAdapter.createFromResource(this,
  R.array.algebra, android.R.layout.simple_list_item_1); 
d.setAdapter(adapt); 
d.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
      int position, long id) {
        if (position == '0') {
            Intent intent = new Intent(Algebra.this, Alqv.class);
            startActivity(intent);
        }
        if (position == '2') {
            Intent intent1 = new Intent(Algebra.this, qfs.class);
            startActivity(intent1);
        }
    });
}

【问题讨论】:

    标签: android listview android-activity android-intent selecteditem


    【解决方案1】:

    这里的位置是整数,所以不要和chars('0','1'...)比较,应该和整数比较。

     if (position == 0) {
         Intent intent = new Intent(Algebra.this, Alqv.class);
            startActivity(intent);
     }
     if (position == 2) {
         Intent intent1 = new Intent(Algebra.this, qfs.class);
            startActivity(intent1);
     }
    

    【讨论】:

      【解决方案2】:

      这里的位置是一个整数。无法与 chars('0','0') 进行比较。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-05-29
        • 1970-01-01
        • 2011-06-17
        • 1970-01-01
        • 1970-01-01
        • 2017-04-22
        相关资源
        最近更新 更多