diff --git a/OSJ Forum/AndroidManifest.xml b/OSJ Forum/AndroidManifest.xml index 8cba99e..f305018 100644 --- a/OSJ Forum/AndroidManifest.xml +++ b/OSJ Forum/AndroidManifest.xml @@ -1,5 +1,5 @@ ITEMS = new ArrayList(); diff --git a/OSJ Forum/src/com/RickBarrette/osj/forum/content/SubForumAdapter.java b/OSJ Forum/src/com/RickBarrette/osj/forum/content/SubForumAdapter.java new file mode 100644 index 0000000..8b789b6 --- /dev/null +++ b/OSJ Forum/src/com/RickBarrette/osj/forum/content/SubForumAdapter.java @@ -0,0 +1,121 @@ +/** + * SubForumAdapter.java + * @date Aug 30, 2012 + * @author ricky barrette + * + * Copyright 2012 Richard Barrette + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package com.RickBarrette.osj.forum.content; + +import java.util.HashMap; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import com.RickBarrette.osj.forum.R; + +/** + * + * @author ricky barrette + */ +public class SubForumAdapter extends BaseAdapter { + + class ViewHolder { + TextView title; + } + + private LayoutInflater mInflater; + private Object[] mSubForums; + + /** + * + * @author ricky barrette + */ + public SubForumAdapter(Context context, int position) { + mInflater = LayoutInflater.from(context); + mSubForums = ForumContent.ITEMS.get(position).getChildren(); + } + + /* (non-Javadoc) + * @see android.widget.Adapter#getCount() + */ + @Override + public int getCount() { + if(mSubForums != null) + return mSubForums.length; + else + return 0; + } + + /* (non-Javadoc) + * @see android.widget.Adapter#getItem(int) + */ + @Override + public HashMap getItem(int position) { + return (HashMap) mSubForums[position]; + } + + /* (non-Javadoc) + * @see android.widget.Adapter#getItemId(int) + */ + @Override + public long getItemId(int position) { + return position; + } + + /* (non-Javadoc) + * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup) + */ + @Override + public View getView(int position, View convertView, ViewGroup parent) { + // A ViewHolder keeps references to children views to avoid unnecessary + // calls to findViewById() on each row. + ViewHolder holder; + + // When convertView is not null, we can reuse it directly, there is no + // need + // to reinflate it. We only inflate a new View when the convertView + // supplied + // by ListView is null. + if (convertView == null) { + convertView = mInflater.inflate(R.layout.forum_item, null); + + // Creates a ViewHolder and store references to the two children + // views + // we want to bind data to. + holder = new ViewHolder(); + holder.title = (TextView) convertView.findViewById(R.id.textView1); + + convertView.setTag(holder); + } else + // Get the ViewHolder back to get fast access to the TextView + // and the ImageView. + holder = (ViewHolder) convertView.getTag(); + + + /* + * Bind the data efficiently with the holder. Remember that you should + * always call setChecked() after calling setOnCheckedChangedListener. + * This will prevent the list from changing the values on you. + */ + holder.title.setText(new String((byte[]) getItem(position).get("forum_name"))); + return convertView; + } + +}