如何使用自定义列表视图将意图对话到下一个活动

时间:2013-11-25 14:10:18

标签: android

如何使用自定义列表视图将意图对话到下一个活动。我有一个对话但我不知道如何打算下一次活动任何人都可以告诉我谢谢你

public class maincard extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menucard);



    final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map;

    /*** Rows 1 ***/
    map = new HashMap<String, String>();
    map.put("ImageID", "1");
    //map.put("ImageDesc", "Sea View1");
    map.put("ImagePath", "pic_a");
    MyArrList.add(map);

    /*** Rows 2 ***/
    map = new HashMap<String, String>();
    map.put("ImageID", "2");
    //map.put("ImageDesc", "Sea View2");
    map.put("ImagePath", "pic_b");
    MyArrList.add(map); 

    /*** Rows 3 ***/
    map = new HashMap<String, String>();
    map.put("ImageID", "3");
    //map.put("ImageDesc", "Sea View 3");
    map.put("ImagePath", "pic_c");
    MyArrList.add(map);

    /*** Rows 4 ***/
    map = new HashMap<String, String>();
    map.put("ImageID", "4");
    //map.put("ImageDesc", "Sea View 4");
    map.put("ImagePath", "pic_d");
    MyArrList.add(map);         

    // listView1
    final ListView lstView1 = (ListView)findViewById(R.id.listView1); 

    lstView1.setAdapter(new ImageAdapter(this,MyArrList));

    // OnClick

    final AlertDialog.Builder imageDialog = new AlertDialog.Builder(this);
    final AlertDialog.Builder imageDialog2 = new AlertDialog.Builder(this);
    final LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);

    lstView1.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {

            View layout = inflater.inflate(R.layout.dialogpreviewcard,
                    (ViewGroup) findViewById(R.id.layout_root));
            ImageView image = (ImageView) layout.findViewById(R.id.fullimage);


            int ResID = getResources().getIdentifier(MyArrList.get(position).get("ImagePath"), "drawable", maincard.this.getPackageName());
            image.setImageResource(ResID);

           //imageDialog.setIcon(android.R.drawable.btn_star_big_on);   
            imageDialog.setTitle("View : " + MyArrList.get(position).get("ImageDesc"));
            imageDialog.setView(layout);
            imageDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener(){

                public void onClick(DialogInterface dialog, int which) {






          }

            });
            imageDialog.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener(){

                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();


                }

            });


            AlertDialog  alert = imageDialog.create();
            alert.show();



        }

    });

}


public class ImageAdapter extends BaseAdapter 
{
    private Context context;
    private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();

    public ImageAdapter(Context c, ArrayList<HashMap<String, String>> list) 
    {
        // TODO Auto-generated method stub
        context = c;
        MyArr = list;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return MyArr.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.cardcolumm, null); 
        }

        // ColImage
        ImageView imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
        imageView.getLayoutParams().height = 100;
        imageView.getLayoutParams().width = 100;
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        int ResID = context.getResources().getIdentifier(MyArr.get(position).get("ImagePath"), "drawable", context.getPackageName());
        imageView.setImageResource(ResID);

        // ColPosition
        TextView txtPosition = (TextView) convertView.findViewById(R.id.ColImgID);
        txtPosition.setPadding(10, 0, 0, 0);
        txtPosition.setText("ID : " + MyArr.get(position).get("ImageID"));

        // ColPicname
        TextView txtPicName = (TextView) convertView.findViewById(R.id.ColImgDesc);
        txtPicName.setPadding(50, 0, 0, 0);
        txtPicName.setText("Desc : " + MyArr.get(position).get("ImageDesc"));


        return convertView;

    }

} 

1 个答案:

答案 0 :(得分:0)

您可以像这样发送您的数据:

 imageDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()   {

            public void onClick(DialogInterface dialog, int which) {

            Intent n = new Intent(SourCeActivity.this , Destination.class);
            n.putExtra("Key" , MyArrList.get(position).get("ImagePath"));
            startActivity(n);
  }

并将此值检索到下一个活动:

 Intent n = getIntent();
 String xyz = n.getStringExtra("key");