Android-Adapter 에서 Intent 를 사용 하여 activity 로 건 너 뛰 기

21542 단어 Android
 Adapter    Activity       
1,         ,context
2,     activity
/**Intent intent=new Intent(mContext,Bingsman.class);//           mContext.startActivity(intent);*/
 
  
 
  
 
  
package com.hxzh.uniwill.lingjian.Adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hxzh.uniwill.lingjian.R;
import com.hxzh.uniwill.lingjian.bean.Data_chaxunrenwu_xiaoxiliebiao;

import java.util.List;

/**
 * Created by pang on 2017/4/10.
 *  listview        
 */
public class HuibaoAdapter extends BaseAdapter {


    private List list1;//    

    private Data_chaxunrenwu_xiaoxiliebiao.ListBean data1;//    

    private List fuJianList;

    private Context context;

    public HuibaoAdapter(Context context, List list1) {
        this.context = context;
        this.list1 = list1;
    }

    public List getList1() {
        return list1;
    }

    public void setList1(List list1) {
        this.list1 = list1;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        if (list1!=null&&list1.size()>0){
            return list1.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return list1.get(position);
    }

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

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
            ViewHolder holder = new ViewHolder();
        if (convertView == null) {
            convertView = View.inflate(context,R.layout.huibao_listview_item, null);

            holder.data = (TextView) convertView.findViewById(R.id.huibao_data);
            holder.name = (TextView) convertView.findViewById(R.id.huibao_name);
            holder.nrirong = (TextView) convertView.findViewById(R.id.huibao_neirong);
            holder.fj1 = (RelativeLayout) convertView.findViewById(R.id.item_fj1);
            holder.fj2 = (RelativeLayout) convertView.findViewById(R.id.item_fj2);
            holder.fj3 = (RelativeLayout) convertView.findViewById(R.id.item_fj3);
            holder.fj4 = (RelativeLayout) convertView.findViewById(R.id.item_fj4);
            holder.fj5 = (RelativeLayout) convertView.findViewById(R.id.item_fj5);
            holder.fj6 = (RelativeLayout) convertView.findViewById(R.id.item_fj6);
            holder.fj7 = (RelativeLayout) convertView.findViewById(R.id.item_fj7);
            holder.fj8 = (RelativeLayout) convertView.findViewById(R.id.item_fj8);
            holder.fj9 = (RelativeLayout) convertView.findViewById(R.id.item_fj9);
            holder.fj10 = (RelativeLayout) convertView.findViewById(R.id.item_fj10);
            holder.fjtext1 = (TextView) convertView.findViewById(R.id.item_fjtext1);
            holder.fjtext2 = (TextView) convertView.findViewById(R.id.item_fjtext2);
            holder.fjtext3 = (TextView) convertView.findViewById(R.id.item_fjtext3);
            holder.fjtext4 = (TextView) convertView.findViewById(R.id.item_fjtext4);
            holder.fjtext5 = (TextView) convertView.findViewById(R.id.item_fjtext5);
            holder.fjtext6 = (TextView) convertView.findViewById(R.id.item_fjtext6);
            holder.fjtext7 = (TextView) convertView.findViewById(R.id.item_fjtext7);
            holder.fjtext8 = (TextView) convertView.findViewById(R.id.item_fjtext8);
            holder.fjtext9 = (TextView) convertView.findViewById(R.id.item_fjtext9);
            holder.fjtext10 = (TextView) convertView.findViewById(R.id.item_fjtext10);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        data1 = list1.get(position);
        fuJianList = list1.get(position).getFuJian();
        holder.data .setText(data1.getCreatetime());
        holder.nrirong.setText(data1.getContent());
        holder.name.setText(data1.getCreator());
        if (fuJianList!=null&&fuJianList.size()>0){
            if (fuJianList.size() == 1){
                holder.fj1.setVisibility(View.VISIBLE);
                holder.fjtext1.setText(fuJianList.get(0).getFileName());
                final String url = fuJianList.get(0).getFileaddressdown();
                holder.fj1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) { //     adapter                   
                        Intent intent= new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        Uri content_url = Uri.parse(url);
                        intent.setData(content_url);
                        context.startActivity(intent);
                    }
                });
            }
        }

        return convertView;
    }
     static class ViewHolder {
        //listview  
         public TextView data;//  
         public TextView name;//  
         public TextView nrirong;//  

         public RelativeLayout fj1;
         public RelativeLayout fj2;
         public RelativeLayout fj3;
         public RelativeLayout fj4;
         public RelativeLayout fj5;
         public RelativeLayout fj6;
         public RelativeLayout fj7;
         public RelativeLayout fj8;
         public RelativeLayout fj9;
         public RelativeLayout fj10;

         public TextView fjtext1;
         public TextView fjtext2;
         public TextView fjtext3;
         public TextView fjtext4;
         public TextView fjtext5;
         public TextView fjtext6;
         public TextView fjtext7;
         public TextView fjtext8;
         public TextView fjtext9;
         public TextView fjtext10;
    }

}

좋은 웹페이지 즐겨찾기