【问题标题】:How to get the text of a TextView from a custom ArrayAdapter如何从自定义 ArrayAdapter 获取 TextView 的文本
【发布时间】:2011-06-22 16:05:53
【问题描述】:

我已经完成了一个自定义的ArrayAdapter,它包含两个视图:一个ImageView 和一个TextView。然后我用这个ArrayAdapter 设置一个ListView。

当我点击ListView 的一行时,onItemClick(...) 被调用,我想这样做:

OnItemClickListener cl = new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(getApplicationContext(), ClubList.class);
        intent.putExtra("CountryName", ((TextView) view).getText());
        startActivity(intent);
    }
};

显然,我不能使用((TextView) view).getText(),因为它是一个包含一个ImageView 和一个TextView 的视图。如何访问TextView 的文本?

【问题讨论】:

  • 请提供您用于实例化自定义适配器的代码。

标签: android textview imageview android-arrayadapter onitemclicklistener


【解决方案1】:

我不知道这些作品有没有

TextView blabla = (TextView)view.findViewById(id.blablaid);

然后

 Intent intent = new Intent(getApplicationContext(), ClubList.class);
        intent.putExtra("CountryName", blabla.getText());
        startActivity(intent);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多