0

如何 ?我有 select1 和 select2 静态 string[] 变量,并声明了 myval、myvals 两个全局变量。如果我从列表项中选择了项目,那么这些项目是可见的,并且下一个活动自定义 listView;

第一个活动:

      l1.setOnItemClickListener(new OnItemClickListener() { 

                 public void onItemClick(AdapterView<?> parent, View view, 
                 int position, long id) { 


 //When clicked, show a toast with the TextView text 
 Toast.makeText(HomeActivity.this, "SELECTED :: " + "item "+ select1[position] + " " + "price"+ select2[position], 
 Toast.LENGTH_SHORT).show(); 


 String s1=select1[position];
GlobalClass.myval.add(s1);

 String s2=select2[position];
 GlobalClass.myvals.add(s2);
 }

高效适配器:

      public static class EfficientAdapter extends BaseAdapter{
     private LayoutInflater mInflater;
     public EfficientAdapter(Context context){
        mInflater=LayoutInflater.from(context);


    }
    public int getCount() {
    return select1.length;
    }
    public Object getItem(int position) {
    return position;
    }
    public long getItemId(int position) {
    return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.list_row,null);
            holder=new ViewHolder();
            holder.Text1=(TextView) convertView.findViewById(R.id.textView1);
            holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
            convertView.setTag(holder);
            }
        else{
            holder=(ViewHolder) convertView.getTag();

        }
        holder.Text1.setText(select1[position]);
        holder.Text2.setText(select2[position]);
        return convertView;
    }
    static class ViewHolder{
        TextView Text1;
        TextView Text2;
        }

下一个活动:

          private static class EfficientAdapter extends BaseAdapter{
    private LayoutInflater mInflater;
    public EfficientAdapter(Context context){
        mInflater=LayoutInflater.from(context);

    // implementation of EfficientAdapter   
    }
    public int getCount() {

        return HomeActivity.select1.length;
    }
    public Object getItem(int position) {

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

        return position ;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

    if(convertView==null){
            convertView=mInflater.inflate(R.layout.list_ticket, null);
            holder=new ViewHolder();
            //holder.Text1=(TextView) convertView.findViewById(R.id.textView1);
            holder.Text2=(TextView) convertView.findViewById(R.id.textView2);
            holder.Text3=(TextView) convertView.findViewById(R.id.textView3);
            convertView.setTag(holder);
        }
        else{
              holder=(ViewHolder)convertView.getTag();
            }

            holder.Text2.setTag(GlobalClass.myval);
            holder.Text3.setTag(GlobalClass.myvals);



        return convertView;
    }
     static class ViewHolder{
        TextView Text1;
        TextView Text2;
        TextView Text3;

    }
}
4

1 回答 1

0

用于从一项活动更改为另一项活动。查看意图 基本上是这样的:

Intent intent = new Intent(getContext(), ActivityToBeStarted.class);
            intent.putExtra("messages", result);
            startActivity(intent);

在 activty 2' 方法中,您从 oncreate 方法开始:

String[] myStringArray = getIntent().getStringArrayExtra("messages");
于 2012-08-02T13:06:43.797 回答