具有意图和自定义ListView的Android



我使用ArrayAdapter自定义ListView,但是当我在智能手机上运行它时,我单击该项目,但它并不是黑暗的,例如不互动。还有一个问题: 当我将IntentTextView一起在ListView中的项目上使用ArrayAdapter时," Error:(64, 71) error: not an enclosing class: PlaylistActivity"

的错误

MainActivity.java

public class MainActivity extends AppCompatActivity {
...
}

AdapterCustom.java

public class AdapterCustom extends BaseAdapter {
...
@Override
public View getView(int i, View view, ViewGroup viewGroup ) {
        final LayoutInflater inflater= (LayoutInflater) mcontext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view=inflater.inflate(layout,null);
    TextView tvFeelOnday= (TextView) view.findViewById(R.id.tv_feel);
    TextView tvFeelDate=(TextView) view.findViewById(R.id.tv_feel_date);
    Feel mFeel= FeelList.get(i);
    tvFeelOnday.setText(mFeel.getmFeelOnDay().toString());
    tvFeelDate.setText(mFeel.getmFeelDate()+"");

    tvFeelOnday.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(mcontext, "Hehe", Toast.LENGTH_SHORT).show();
            Intent intent;
            intent = new Intent(this, MainActivity.class);// an error
        }
    });
    return view;
}

您必须使用您的活动上下文并使用该上下文来创建新活动。制作一个用于初始化上下文的构造函数。

public AdapterCustom(Context context) {
          this.context = context;     
     }

最新更新