Android Open Source - divider List View Adapter






From Project

Back to project page divider.

License

The source code is released under:

Apache License

If you think the Android project divider 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 se.urvancevav.divider;
/*/*from w  ww .j a  va  2  s.co  m*/
 * 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.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.text.NumberFormat;

public class ListViewAdapter extends ArrayAdapter<ListItem> {

    public ListViewAdapter(Context context, int resource) {
        super(context, resource);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v = convertView;

        ListViewHolder holder = new ListViewHolder();

        // First let's verify the convertView is not null
        if (convertView == null) {
            // This a new view we inflate the new layout
            LayoutInflater inflater = LayoutInflater.from(getContext());
            v = inflater.inflate(R.layout.list_view_row_layout, null);
            // Now we can fill the layout with the right values
            TextView idView = (TextView) v.findViewById(R.id.list_view_row_id);
            TextView nameView = (TextView) v.findViewById(R.id.list_view_row_name);
            TextView paidSumView = (TextView) v.findViewById(R.id.list_view_row_paid_sum);
            TextView returnSumView = (TextView) v.findViewById(R.id.list_view_row_return_sum);

            holder.idView = idView;
            holder.nameView = nameView;
            holder.paidSumView = paidSumView;
            holder.returnSumView = returnSumView;
            v.setTag(holder);
        } else {
            holder = (ListViewHolder) v.getTag();
        }

        ListItem item = getItem(position);

        holder.idView.setText((position + 1) + ".");
        holder.nameView.setText(item.getName());

        NumberFormat formatter = NumberFormat.getCurrencyInstance();

        holder.paidSumView.setText(formatter.format(item.getPaidAmount()));
        holder.returnSumView.setText(formatter.format(item.getReturnAmount()));
        return v;
    }

    private static class ListViewHolder {
        public TextView idView;
        public TextView nameView;
        public TextView paidSumView;
        public TextView returnSumView;
    }
}




Java Source Code List

se.urvancevav.divider.AddNewItemDialog.java
se.urvancevav.divider.AddNewItemEvent.java
se.urvancevav.divider.ApplicationTest.java
se.urvancevav.divider.ListItem.java
se.urvancevav.divider.ListViewAdapter.java
se.urvancevav.divider.ListViewFragment.java
se.urvancevav.divider.MainActivity.java
se.urvancevav.divider.SwipeDismissListViewTouchListener.java