0

どうやって ?select1 と select2 の静的 string[] 変数があり、myval、myvals の 2 つのグローバル変数を宣言しました。リスト項目から項目を選択した場合、項目が表示され、次のアクティビティ カスタム 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);

アクティビティ 2' メソッドでは、oncreate メソッドで開始します。

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