如何在Popupwindow \ popupview中使用Listadaptor类

时间:2016-04-12 06:21:18

标签: popupwindow listadapter

我正在使用Listadaptor类来生成列表中正常工作的视图。同样的事情我想在弹出窗口上使用,但它会抛出空指针异常 这是我的代码,我在调用listadaptor类

private void showListPopUp() 
{
    try
    {
        LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);

        View popupView = layoutInflater.inflate(R.layout.popuptktlist, null);
        final PopupWindow popupWindow = new PopupWindow(popupView,android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

        lvTktList = (ListView) findViewById(R.id.listView_trbl_tkt_list);
        tvTicketNo  = (TextView)popupView.findViewById(R.id.tv_tktlist_ct);
        tvCallNat  = (TextView)popupView.findViewById(R.id.tv_tktlist_cn);
        tvCustGet  = (TextView)popupView.findViewById(R.id.tv_tktlist_custn);
        tvCityGet  = (TextView)popupView.findViewById(R.id.tv_tktlist_city);
        tvProbGet  = (TextView)popupView.findViewById(R.id.tv_tktlist_prob);
        popupWindow.showAtLocation(popupView, Gravity.CENTER, 10,10);

        lvTktList.setAdapter( new TicketListAdapter(getBaseContext(), getRecordDetailFromDB() ) );
    }
    catch(Exception ex)
    {
        Toast.makeText(getBaseContext(), ex.toString(), Toast.LENGTH_LONG).show();
    }
}

这是我的Listadaptor类

package lipicrm.atmcrm;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class TicketListAdapter extends android.widget.BaseAdapter
{
public static ArrayList<TktList> tktList = null;
private LayoutInflater inflater = null;
Context context = null;

public TicketListAdapter(Context context, ArrayList<TktList> tsList) 
{
   this.context = context;
   tktList = tsList;
   inflater = LayoutInflater.from(this.context);
}

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

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


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

@Override
public View getView(int position, View convertView, ViewGroup arg2) 
{
//      Toast.makeText(context, "44", Toast.LENGTH_LONG).show();
    try
    {
      ViewHolder holder;
      if (convertView == null) 
      {
          convertView = inflater.inflate(R.layout.popuptktlist_recorddtl,null);
          holder = new ViewHolder();
          holder.txt_CallTicket     = (TextView) convertView.findViewById(R.id.tv_tktlist_ct);
          holder.txt_CallNature     = (TextView) convertView.findViewById(R.id.tv_tktlist_cn);
          holder.txt_CustName       = (TextView) convertView.findViewById(R.id.tv_tktlist_custn);
          holder.txt_CityName       = (TextView) convertView.findViewById(R.id.tv_tktlist_city);
          holder.txt_Prob       = (TextView) convertView.findViewById(R.id.tv_tktlist_prob);

          convertView.setTag(holder);
      } 
      else 
      {
          holder = (ViewHolder) convertView.getTag();
      }
      holder.txt_CallTicket.setText(tktList.get(position).getCallTNo());
      holder.txt_CallNature.setText(tktList.get(position).getCallNature());
      holder.txt_CustName.setText(tktList.get(position).getAbrVtn());
      holder.txt_CityName.setText(tktList.get(position).getCityName());
      holder.txt_Prob.setText(tktList.get(position).getProbDesc());

    }
    catch(Exception ex)
    {
        Toast.makeText(context, ex.toString(), Toast.LENGTH_LONG).show();
    }
    return convertView;
}

static class ViewHolder 
{
    TextView txt_CallTicket;
    TextView txt_CustName;
    TextView txt_CityName;
    TextView txt_CallNature;
    TextView txt_Prob;
}
}
如果我使用没有popwindow的代码

列表正在生成

0 个答案:

没有答案