从BaseAdapter尝试startActivity时出现未知错误

时间:2015-08-25 16:06:24

标签: android android-intent baseadapter custom-lists start-activity

我在android中进行自定义ListView,每个项目都有一个共享按钮。单击按钮后,它必须创建选择器(Facebook等)。但是当我点击它时,应用程序崩溃,logcat什么也没显示。请帮帮我 这是我的适配器:

public class AdapterQ extends BaseAdapter {
List<Quotes> sss;
Context ss;
Intent sendIntent;
public AdapterQ(Context ss, List<Quotes>items){
    this.ss = ss;
    this.sss = items;

}

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

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

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater)
                ss.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.quoteitem, null);
    }

    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.legendImage);
    final TextView tvTitle = (TextView) convertView.findViewById(R.id.legendName);
    ImageView ssss= (ImageView) convertView.findViewById(R.id.Nation);
    final Quotes quotes = sss.get(position);

    imgIcon.setImageResource(quotes.getIcon());
    tvTitle.setText(quotes.getText());
    ssss.setImageResource(R.mipmap.ic_share_black_24dp);
    ssss.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           sendIntent =new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, tvTitle.getText());
            sendIntent.setType("text/plain");
            ss.startActivity(Intent.createChooser(sendIntent, "Поделиться..."));
        }
    });
    return convertView;
}

}   引号:

public class Quotes {
private String mText;
private int mIcon;

public String getText() {
    return mText;
}

public void setText(String mText) {
    this.mText = mText;
}

public int getIcon() {
    return mIcon;
}

public void setIcon(int mIcon) {
    this.mIcon = mIcon;
}

} 片段:

public class AllFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rrrr = inflater.inflate(R.layout.fragment_all, container, false);
    String[] ss = getResources().getStringArray(R.array.Абай);
    String[] qq = getResources().getStringArray(R.array.Абылай);
    String[] sr = new String[ss.length + qq.length];
    System.arraycopy(ss, 0, sr, 0, ss.length);
    System.arraycopy(qq, 0, sr, ss.length, qq.length);
    ListView se = (ListView) rrrr.findViewById(R.id.listView2);
    shuffleArray(sr);

    List<Quotes> ser = new ArrayList<Quotes>();
    for (int s = 0; s<sr.length; s++){

        if(Arrays.asList(ss).contains(sr[s]) ){
            Quotes quotes = new Quotes();
            quotes.setText(sr[s]);
            quotes.setIcon(R.drawable.abay);
            ser.add(quotes);
        } else if(Arrays.asList(qq).contains(sr[s])){
            Quotes quotes = new Quotes();
            quotes.setText(sr[s]);
            quotes.setIcon(R.drawable.abylai);
            ser.add(quotes);
        }
    }
    AdapterQ ses = new AdapterQ(getActivity().getApplicationContext(), ser);


    se.setAdapter(ses);

    return rrrr;

}

1 个答案:

答案 0 :(得分:2)

下面:

AdapterQ ses = new AdapterQ(getActivity().getApplicationContext(), ser);

试试这个:

AdapterQ ses = new AdapterQ(getActivity(), ser);