自定义ListViews,ArrayLists,ArrayAdapters

时间:2018-04-10 09:45:00

标签: android listview arraylist custom-arrayadapter

我正在尝试为学生构建一个考勤管理器应用程序,我正在使用自定义ListView来显示主题名称和最小出勤率。

这些是我面临的问题:

1)我希望我的第一个列表项是"添加主题项"并且点击它会转到x并通过AddSubjectActivity存储所有内容。

2)在SharedPreferences中按下提交按钮后,我希望下一个列表项说出"点击添加主题"等等。

3)基本上,假设AddSubjectActivity有5个项目,点击每个项目会将我带到AddSubject活动,但是在其中显示与被点击的相应ListView相对应的信息。

这是我的代码:

Class CustomAdapter

list Item

SecondActivity:包含ListView的活动

    public class CustomAdapter extends BaseAdapter{
    String [] result;
    Context context;
    int [] imageId;
    private static LayoutInflater inflater=null;
    public CustomAdapter(SecondActivity mainActivity, String[] prgmNameList, int[] prgmImages) {
        // TODO Auto-generated constructor stub
        result=prgmNameList;
        context=mainActivity;
        imageId=prgmImages;
        inflater = ( LayoutInflater )context.
                    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return result.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public class Holder
    {
        TextView tv;
        ImageView img;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder=new Holder();
        SecondActivity second=new SecondActivity();
        View rowView;
        rowView = inflater.inflate(R.layout.program_list, null);
        holder.tv=(TextView) rowView.findViewById(R.id.textView);
        holder.img=(ImageView) rowView.findViewById(R.id.statsImageView);
        holder.tv.setText(result[position]);
        holder.img.setImageResource(imageId[position]);
        rowView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                Toast.makeText(context, "You Clicked "+result[position], Toast.LENGTH_LONG).show();
                context.startActivity(new Intent(context, AddSubject.class));
            }
        });





        return rowView;
    }

}

enter image description here

0 个答案:

没有答案