Android Open Source - Android-1 Ivo Adapter






From Project

Back to project page Android-1.

License

The source code is released under:

MIT License

If you think the Android project Android-1 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 com.example.georgi.mehadapter;
//from   www. j  a  v  a  2s.  c  o m
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by georgi on 11/19/14.
 */
public class IvoAdapter extends BaseAdapter {

    public void add(Contact contact) {
        contactList.add(contact);
    }

    private final static class ViewHolder {
        public TextView name;
        public TextView number;
    }

    private List<Contact> contactList = new ArrayList<Contact>() {{
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));

        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
        add(new Contact("Ivo", "8521958", -1));
    }};

    @Override
    public int getCount() {
        return contactList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, final ViewGroup viewGroup) {
        ////

        LinearLayout layout = null;
        if (convertView != null) {
            layout = (LinearLayout) convertView;
        } else {
            layout = (LinearLayout) LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.linear_layout, null, false);

            TextView name = (TextView) layout.findViewById(R.id.name);
            TextView number = (TextView) layout.findViewById(R.id.number);

            ViewHolder viewHolder = new ViewHolder();
            viewHolder.name = name;
            viewHolder.number = number;

            layout.setTag(viewHolder);

            layout.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(viewGroup.getContext());

                    AlertDialog dialog = builder.setTitle("Dialog").setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(viewGroup.getContext(), "Yes clicked", Toast.LENGTH_SHORT).show();
                        }
                    }).setNegativeButton("No", null).create();

                    dialog.show();
                    return false;
                }   
            });
        }


        Contact contact = contactList.get(position);
        ViewHolder holder = (ViewHolder) layout.getTag();
        holder.name.setText(contact.getName());
        holder.number.setText(contact.getNumber());


        return layout;
    }
}




Java Source Code List

com.example.georgi.mehadapter.ApplicationTest.java
com.example.georgi.mehadapter.Contact.java
com.example.georgi.mehadapter.IvoAdapter.java
com.example.georgi.mehadapter.MyActivity.java
com.example.georgi.puzzle.ApplicationTest.java
com.example.georgi.puzzle.BuildConfig.java
com.example.georgi.puzzle.PuzzleActivity.java
com.example.georgi.resourcesrecreate.AppContext.java
com.example.georgi.resourcesrecreate.ApplicationTest.java
com.example.georgi.resourcesrecreate.LoginActivity.java
com.example.georgi.resourcesrecreate.MyActivity.java
com.example.georgi.resourcesrecreate.PlusBaseActivity.java
com.example.georgi.sqliteexample.ApplicationTest.java
com.example.georgi.sqliteexample.FluentApiBuilder.java
com.example.georgi.sqliteexample.Losers.java
com.example.georgi.sqliteexample.MyActivity.java
com.example.gestureimageview.GestureImageActivity.java