Android Open Source - RealtimeStorage-Android Todo Custom Adapter






From Project

Back to project page RealtimeStorage-Android.

License

The source code is released under:

MIT License

If you think the Android project RealtimeStorage-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package adapters;
//from w w w. j ava  2 s.co  m
import java.util.ArrayList;
import java.util.LinkedHashMap;

import co.realtime.sample.R;
import co.realtime.storage.ItemAttribute;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.TextView;


public class TodoCustomAdapter extends ArrayAdapter<LinkedHashMap<String, ItemAttribute>>{
  Context context;
  int layoutResId;
  ArrayList<LinkedHashMap<String, ItemAttribute>> data = new ArrayList<LinkedHashMap<String, ItemAttribute>>();
  TodoCustomAdapterReceiver receiver;
  
  public TodoCustomAdapter(Context context, int layoutResourceId, ArrayList<LinkedHashMap<String, ItemAttribute>> data) {
    super(context, layoutResourceId, data);
    this.context = context;
    this.layoutResId = layoutResourceId;
    this.data = data;
  }
  

  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ItemHolder holder = null;

    if(row == null){
      LayoutInflater inflater = ((Activity) context).getLayoutInflater();
      row = inflater.inflate(layoutResId, parent, false);
      holder = new ItemHolder();
      holder.tvTask = (TextView) row.findViewById(R.id.textView1);
      holder.ibState = (ImageButton) row.findViewById(R.id.button1);
      holder.ibRemove = (ImageButton) row.findViewById(R.id.button2);
      row.setTag(holder);
    } else {
      holder = (ItemHolder) row.getTag();
    }
    LinkedHashMap<String, ItemAttribute> item = data.get(position);
    holder.tvTask.setText(item.get("task").toString());
    if(item.get("state").compareTo(new ItemAttribute(1))==0){
      holder.ibState.setBackgroundResource(R.drawable.check_on1);
    } else {
      holder.ibState.setBackgroundResource(R.drawable.check_off1);
    }

    holder.ibRemove.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        if(receiver!=null)
          receiver.btRemovePressed(position);
      }
    });

    holder.ibState.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        if(receiver!=null)
          receiver.btStatePressed(position);
      }
    });

    return row;
  }
  
  public void setActionsReceiver(TodoCustomAdapterReceiver receiver){
    this.receiver = receiver;
  }
  
  public interface TodoCustomAdapterReceiver{
    public void btRemovePressed(int position);
    public void btStatePressed(int position);
  }
  
  static class ItemHolder {
    TextView tvTask;
    ImageButton ibState;
    ImageButton ibRemove;
  }

}




Java Source Code List

adapters.TodoCustomAdapter.java
co.realtime.sample.ApplicationTest.java
co.realtime.sample.MainActivity.java
co.realtime.storage.ApplicationTest.java
co.realtime.storage.EventCollection.java
co.realtime.storage.Event.java
co.realtime.storage.Filter.java
co.realtime.storage.ItemAttribute.java
co.realtime.storage.ItemRef.java
co.realtime.storage.ItemSnapshot.java
co.realtime.storage.LHMItemsComparator.java
co.realtime.storage.OnRestCompleted.java
co.realtime.storage.PostBodyBuilder.java
co.realtime.storage.ProcessRestResponse.java
co.realtime.storage.RestWebservice.java
co.realtime.storage.Rest.java
co.realtime.storage.StorageContext.java
co.realtime.storage.StorageRef.java
co.realtime.storage.TableRef.java
co.realtime.storage.TableSnapshot.java
co.realtime.storage.entities.Heartbeat.java
co.realtime.storage.entities.IORMapping.java
co.realtime.storage.entities.KeySchema.java
co.realtime.storage.entities.Key.java
co.realtime.storage.entities.TableMetadata.java
co.realtime.storage.entities.Throughput.java
co.realtime.storage.ext.OnBooleanResponse.java
co.realtime.storage.ext.OnError.java
co.realtime.storage.ext.OnHeartbeat.java
co.realtime.storage.ext.OnItemSnapshot.java
co.realtime.storage.ext.OnPresence.java
co.realtime.storage.ext.OnReconnected.java
co.realtime.storage.ext.OnReconnecting.java
co.realtime.storage.ext.OnTableCreation.java
co.realtime.storage.ext.OnTableMetadata.java
co.realtime.storage.ext.OnTableSnapshot.java
co.realtime.storage.ext.OnTableUpdate.java
co.realtime.storage.ext.StorageException.java
config.Config.java
handlers.StorageHandler.java
helpers.ListNameHelper.java
listeners.ClickListener.java
listeners.EditorListener.java
ui.MyViewPager.java