Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

    private Context mContext;
    private List<MyList> mItems;
    private int item_layout;


    public MyAdapter(Context mContext, List<MyList> items, int item_layout) {
        this.mContext = mContext;
        this.mItems = items;
        this.item_layout = item_layout;
    }

    @Override
    public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View mView = inflater.inflate(R.layout.simpleitem, parent,false);
        return new ViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(MyAdapter.ViewHolder holder, int position) {
        MyList item = mItems.get(position);
        holder.mTextTemp.setText(item.getTemp());
        holder.mTextData.setText(item.getData());
        holder.mImageView.setBackgroundResource(item.getImage());
    }

    @Override
    public int getItemCount() {
        return this.mItems.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        public ImageView mImageView;
        public TextView mTextData;
        public TextView mTextTemp;


        public ViewHolder(View itemView) {
            super(itemView);

            mImageView = (ImageView) itemView.findViewById(R.id.backImage);
            mTextData = (TextView) itemView.findViewById(R.id.textData);
            mTextTemp = (TextView) itemView.findViewById(R.id.textTemp);
        }
    }
}

public class FragmentPage2 extends Fragment {

    List<MyList> myList;
    public DataBase db;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        db = new DataBase(getActivity(), "THERMO.db", null, 1);
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        db.insert("11", "11", "1");
        db.insert("22", "22", "2");

        initData();
        View layout = inflater.inflate(R.layout.fragment_page2, container, false);

        RecyclerView mRecyclerView = (RecyclerView)layout.findViewById(R.id.recyclerView);
        mRecyclerView.setHasFixedSize(true);

        RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(layout.getContext());
        mRecyclerView.setLayoutManager(mLayoutManager);

        RecyclerView.Adapter mAdapter;


        Log.v("11", "11");
        mAdapter = new MyAdapter(layout.getContext(), myList, R.layout.simpleitem);
        Log.v("22", "22");
        mRecyclerView.setAdapter(mAdapter);


        MainActivity.selectButton(1);
        return layout;
    }

    private void initData()
    {
        myList = new ArrayList<MyList>();
        myList = db.selectData(myList, "BODY_TEMP", "DATE, BODY_TEMP");
        Log.v("gggg" , myList.toString());
    }
}

public List selectData(List myList, String table, String field)
{
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.rawQuery("select " + field + " from " + table, null);
    while(cursor.moveToNext())
    {
        myList.add(cursor.getString(0));
    }
    return myList;
}

share|improve this question
2  
What is the exact error message and where in your code does it happen? This error means you are trying to cast something that is not a String, to a String. That doesn't work. Casting is not a way to automatically convert objects from one type to another. – Jesper Jul 20 at 8:04
    
Can you please post the line where the error occurs? We need more information from your exception to be able to help! – Draken Jul 20 at 8:06
    
MyList item = mItems.get(position); public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> error... i error idon't no help – Jinho Kang Jul 20 at 8:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.