From 3301d8b4fb3b70901b5c612310f9e9643d23f524 Mon Sep 17 00:00:00 2001 From: madiyar Date: Tue, 23 Feb 2016 14:36:24 +0600 Subject: [PATCH] Created suggestion adapter --- .../schabi/newpipe/SuggestionListAdapter.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java diff --git a/app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java b/app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java new file mode 100644 index 000000000..bdb6c36ef --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/SuggestionListAdapter.java @@ -0,0 +1,75 @@ +package org.schabi.newpipe; + +import android.content.Context; +import android.database.Cursor; +import android.database.MatrixCursor; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CursorAdapter; +import android.widget.TextView; + +import java.util.ArrayList; + +/** + * Created by Madiyar on 23.02.2016. + */ +public class SuggestionListAdapter extends CursorAdapter { + + private ArrayList suggestions; + private String[] columns = new String[]{"_id", "title"}; + + public SuggestionListAdapter(Context context) { + super(context, null, false); + + } + + public ArrayList getSuggestions() { + return suggestions; + } + + public void setSuggestions(ArrayList suggestions) { + this.suggestions = suggestions; + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + ViewHolder viewHolder; + + View view = LayoutInflater.from(context).inflate(android.R.layout.simple_list_item_1, parent, false); + viewHolder = new ViewHolder(); + viewHolder.suggestionTitle = (TextView) view.findViewById(android.R.id.text1); + view.setTag(viewHolder); + + + return view; + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + ViewHolder viewHolder = (ViewHolder) view.getTag(); + viewHolder.suggestionTitle.setText(cursor.getString(1)); + } + + + public void updateAdapter(ArrayList suggestions) { + MatrixCursor cursor = new MatrixCursor(columns); + int i = 0; + for (String s : suggestions) { + String[] temp = new String[2]; + temp[0] = Integer.toString(i); + temp[1] = s; + i++; + cursor.addRow(temp); + } + changeCursor(cursor); + } + + public String getSuggestion(int position) { + return ((Cursor) getItem(position)).getString(1); + } + + private class ViewHolder { + public TextView suggestionTitle; + } +}