在getView中编写方法

时间:2016-09-20 19:51:39

标签: java android adapter getview

我正在尝试在getView()适配器中的listview内编写一个方法,如下所示

public class CardsDataAdapter extends ArrayAdapter<String>  {
    public CardsDataAdapter(Context context) {super(context, R.layout.view);}

    @Override
    public View getView(int position, final View contentView, ViewGroup parent){
       TextView text = (TextView)(contentView.findViewById(R.id.content));
       text.setText(getItem(position));

    //This is the method I want to trigger, but says it's not allowed to write here
     public static void triggerThis(){
    dothisthing.method(getItem(position))
    }

return contentView;}

我需要一个静态方法,因为我想在另一个类中调用它。我到处寻找其他解决方案来触发这种行动,但没有成功。

2 个答案:

答案 0 :(得分:1)

   @Override
 public View getView(int position, final View contentView, ViewGroup parent){
   TextView text = (TextView)(contentView.findViewById(R.id.content));
   text.setText(getItem(position));

    triggerThis();
 return contentView;}

 public static void triggerThis(){
     dothisthing.method(getItem(position))
    }

答案 1 :(得分:0)

您不能以这种方式调用函数public static void triggerThis()来调用您只使用函数或方法名称的函数。例如triggerThis()