Back to project page SimpleReader.
The source code is released under:
Apache License
If you think the Android project SimpleReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.dreamteam.app.adapter; // w w w . ja v a 2s.co m import java.util.ArrayList; import android.content.Context; import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageButton; import android.widget.TextView; import com.dreamteam.app.commons.SectionHelper; import com.dreamteam.app.db.DbManager; import com.dreamteam.app.db.FeedDBManager; import com.dreamteam.app.entity.Feed; import com.dreamteam.app.ui.MainActivity; import com.dreateam.app.ui.R; public class CategoryDetailAdapter extends BaseAdapter { public static final String tag = "CategoryDetailAdapter"; private LayoutInflater inflater; private Context context; private ArrayList<Feed> feeds; private String tableName;//?????????? public static final String SECTION_TABLE_NAME = "section"; private int[] imgIds = { R.drawable.add, R.drawable.added }; public CategoryDetailAdapter(Context context, ArrayList<Feed> feeds, String tableName) { this.context = context; this.feeds = feeds; this.tableName = tableName; inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } public void updateData(ArrayList<Feed> feeds) { this.feeds = feeds; notifyDataSetChanged(); } @Override public int getCount() { return feeds.size(); } @Override public Object getItem(int position) { return feeds.get(position); } @Override public long getItemId(int id) { return id; } @Override public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if(convertView == null) { convertView = inflater.inflate(R.layout.category_detail_item, null); holder = new ViewHolder(); holder.feedTitle = (TextView) convertView.findViewById(R.id.category_detail_feed_title); holder.addBtn = (ImageButton) convertView.findViewById(R.id.category_detail_add); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.addBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Feed feed = feeds.get(position); String title = feed.getTitle(); String url = feed.getUrl(); Intent intent = new Intent(); int state = 0;//?????? DbManager mgr = new DbManager(context, DbManager.DB_NAME, null, 1); //??????????????? if(feed.isSelected()) { //??????feeds feed.setSelectStatus(state); holder.addBtn.setImageResource(imgIds[0]); //??????? intent.putExtra("url", feed.getUrl()); intent.setAction(MainActivity.ACTION_DELETE_SECTION); context.sendBroadcast(intent); //??section????????? SectionHelper.removeRecord(mgr.getWritableDatabase(), url); //??feed.db??????????0 new FeedDBManager(context, FeedDBManager.DB_NAME, null, 1) .updateState(tableName, state, url); return; } //?????????? state = 1; feed.setSelectStatus(state); holder.addBtn.setImageResource(imgIds[1]); //??????? intent.setAction(MainActivity.ACTION_ADD_SECTION); context.sendBroadcast(intent); //??section? SQLiteDatabase db = mgr.getWritableDatabase(); SectionHelper.insert(db, tableName, title, url); db.close(); //??feed.db??????????1 FeedDBManager feedHelper = new FeedDBManager(context, FeedDBManager.DB_NAME, null, 1); feedHelper.updateState(tableName,state, url); } }); Feed feed = feeds.get(position); holder.feedTitle.setText((CharSequence) feed.getTitle()); //addBtn??????? holder.addBtn.setImageResource(imgIds[feed.getSelectStatus()]); return convertView; } private static final class ViewHolder { TextView feedTitle; ImageButton addBtn; } }