Android 将字符串getIntent传递给另一个活动中的Listview

Android 将字符串getIntent传递给另一个活动中的Listview,android,adapter,Android,Adapter,我想传递此代码标记器,以便在下一个活动中填充listview。Im使用getintent()和自定义适配器连接到下一个活动。有人告诉我应该定制适配器 Intent intent = new Intent(ClaimVoucherActivity.this,ClaimVoucherDetailsActivity.class); intent.putExtra("customerID", customerID);

我想传递此代码标记器,以便在下一个活动中填充listview。Im使用getintent()和自定义适配器连接到下一个活动。有人告诉我应该定制适配器

Intent intent = new Intent(ClaimVoucherActivity.this,ClaimVoucherDetailsActivity.class);
                        intent.putExtra("customerID", customerID);
                        intent.putExtra("type", type);
                        intent.putExtra("name", name);
                        intent.putExtra("email", email);
                        intent.putExtra("voucher", voucher);
                        intent.putExtra("branch", branch);
                        intent.putExtra("issued", issued);
                        intent.putExtra("expiration", expiration);
                        intent.putExtra("status", status);
                        intent.putExtra("vouchername", vouchername);
                        intent.putExtra("employeeid", employeeid);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
这是自定义适配器

public class ClaimVoucherAdapter extends ArrayAdapter<ClaimVoucherActivity> {

private ArrayList<ClaimVoucherActivity> items;
private LayoutInflater vi;

TextView tvName,tvEmail,tvVoucherCode,tvIssueBranch,tvDateIssued,tvExpiration,tvStatus,tvVoucherSource;
public ClaimVoucherAdapter(Context context, int textViewResourceId, ArrayList<ClaimVoucherActivity> items) {
        super(context, textViewResourceId, items);
        this.items = items;
        vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

        ClaimVoucherActivity o = items.get(position);
        if (o != null) {

            tvName = (TextView) v.findViewById(R.id.tvName);
            tvEmail = (TextView)v.findViewById(R.id.tvEmail);
            tvVoucherCode = (TextView)v.findViewById(R.id.tvVoucherCode);
            tvIssueBranch = (TextView)v.findViewById(R.id.tvIssuingBranch);
            tvDateIssued = (TextView)v.findViewById(R.id.tvDateIssued);
            tvExpiration = (TextView)v.findViewById(R.id.tvExpirationDate);
            tvStatus = (TextView)v.findViewById(R.id.tvStatus);     
            tvVoucherSource = (TextView)v.findViewById(R.id.tvVoucherSource);


        }
        return v;
}
}

您只需将所有数据添加到列表中即可

List<String> myList = new ArrayList<String>();
myList.add(selected);
myList.add(sType);
myList.add(sName);
myList.add(sEmail);
myList.add(sVoucher); //Add same for other which is remaining.
现在在这里

 public class ClaimVoucherAdapter extends ArrayAdapter<ClaimVoucherActivity> {

 private ArrayList<String> items;
 private LayoutInflater vi;

 TextView tvName,tvEmail,tvVoucherCode,tvIssueBranch,tvDateIssued,tvExpiration,tvStatus,tvVoucherSource;
 public ClaimVoucherAdapter(Context context, int textViewResourceId,  ArrayList<String> items) {
    super(context, textViewResourceId, items);
    this.items = items;
    vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 }

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

    //ClaimVoucherActivity o = items.get(position);
   // if (o != null) {

        tvName = (TextView) v.findViewById(R.id.tvName);
        tvEmail = (TextView)v.findViewById(R.id.tvEmail);
        tvVoucherCode = (TextView)v.findViewById(R.id.tvVoucherCode);
        tvIssueBranch = (TextView)v.findViewById(R.id.tvIssuingBranch);
        tvDateIssued = (TextView)v.findViewById(R.id.tvDateIssued);
        tvExpiration = (TextView)v.findViewById(R.id.tvExpirationDate);
        tvStatus = (TextView)v.findViewById(R.id.tvStatus);     
        tvVoucherSource = (TextView)v.findViewById(R.id.tvVoucherSource);

        tvEmail.setText(items.get(position).toString());
        // Now same do for all others Strings.
    //}
    return v;
}
}
公共类ClaimVoucherAdapter扩展了ArrayAdapter{
私有ArrayList项;
私人停车场6号;
text查看tvName、tvEmail、tvVoucherCode、tvIssueBranch、tvDateIssued、tvExpiration、tvStatus、tvVoucherSource;
public-ClaimVoucherAdapter(上下文上下文、int-textViewResourceId、ArrayList项){
super(上下文、textViewResourceId、项);
这个项目=项目;
vi=(LayoutInflater)context.getSystemService(context.LAYOUT\u充气机\u服务);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图v=转换视图;
//ClaimVoucherO=items.get(位置);
//如果(o!=null){
tvName=(TextView)v.findViewById(R.id.tvName);
TveEmail=(TextView)v.findViewById(R.id.TveEmail);
tvVoucherCode=(TextView)v.findViewById(R.id.tvVoucherCode);
tvisuebranch=(TextView)v.findviewbyd(R.id.tvisuingbranch);
TVDateIssuited=(TextView)v.findViewById(R.id.TVDateIssuited);
tvExpiration=(TextView)v.findViewById(R.id.tvExpirationDate);
tvStatus=(文本视图)v.findViewById(R.id.tvStatus);
TVvouchSource=(TextView)v.findViewById(R.id.TVvouchSource);
setText(items.get(position.toString());
//现在,对所有其他字符串也是如此。
//}
返回v;
}
}

您可以在下面这样的活动中获取这些数据

Intent i = getIntent();
customerID= i.getStringExtra("customerID");
type= i.getStringExtra("type");
name= i.getStringExtra("name");
...............
...............
然后创建列表并将数据添加到列表中。创建适配器并将列表设置为适配器后

添加到列表中

ArrayList<String> list = new ArrayList<String>();
list.add(customerID);
list.add(type);
..................
..........
ArrayList list=new ArrayList();
列表。添加(customerID);
列表。添加(类型);
..................
..........
然后添加到适配器

ArrayAdapter<String> adapter = new ArrayAdapter<String>(YourActivity.this,android.R.layout.simple_list_item_1, list);
list.setAdapter(adapter);
ArrayAdapter=newArrayAdapter(YourActivity.this,android.R.layout.simple\u list\u item\u 1,list);
list.setAdapter(适配器);

下面是您的列表视图

,那么问题出在哪里?任何问题或错误??问题是我不知道如何做。在下一个活动中检索此所有字符串并将其添加到列表中我添加了自定义适配器。请检查有何错误,如何使用自定义适配器将字符串放入listview?但是数据/字符串来自其他活动。这就是我使用getIntent()的原因,我知道这一点。您只需在ClaimVoucherDetailsActivity中添加数据,字符串是从web返回的。我不手动放。我在代码中添加了它。好的,我现在正在编辑我的代码。请不要离开我需要你的帮助。@jajaja你会完全困惑的。。。只需将您的数据传递到您解析的位置,并根据我的答案将其添加到您的活动中。您得到答案了吗?我正在从web添加字符串
ArrayList<String> list = new ArrayList<String>();
list.add(customerID);
list.add(type);
..................
..........
ArrayAdapter<String> adapter = new ArrayAdapter<String>(YourActivity.this,android.R.layout.simple_list_item_1, list);
list.setAdapter(adapter);