0

我想更改表格列表视图上的特定图像,当用户单击列表视图的任何图像视图然后打开对话框时,如果用户单击确定按钮确定对话框,则应更改特定图像。我已经创建了代码,但它不能正常工作。

public void Display_Description(String get_Desc) {



    setDESCRIPTION = get_Desc;

    TableLayout tbl = new TableLayout(Job_Description.this);
    mylist = new ArrayList<String>();

    Document doc = XMLfunctions.XMLfromString(JobSearch.line);

    // Parent node is JOB
    NodeList nodes = doc.getElementsByTagName("JOB");

    for (int i = 0; i < nodes.getLength(); i++) {
        Element e = (Element) nodes.item(i);
        pass_value.add(XMLfunctions.getValue(e, "id"));

        if (!("null").equals(XMLfunctions.getValue(e, "location"))) {
            mylist.add(XMLfunctions.getValue(e, "location"));
            city_name.add(XMLfunctions.getValue(e, "location"));


        } else {
            mylist.add(" ");
        }
        if (!("null").equals(XMLfunctions.getValue(e, "title"))) {
            mylist.add(XMLfunctions.getValue(e, "title"));
            business_name.add(XMLfunctions.getValue(e, "title"));



        } else {
            mylist.add(" ");
        }
        if (!("null").equals(XMLfunctions.getValue(e, "state"))) {
            mylist.add(XMLfunctions.getValue(e, "state"));
            state_name.add(XMLfunctions.getValue(e, "state"));



        } else {
            mylist.add(" ");
        }

        if (!("null").equals(XMLfunctions.getValue(e, "company"))) {
            mylist.add(XMLfunctions.getValue(e, "company"));
            company_name.add(XMLfunctions.getValue(e, "company"));


        } else {
            mylist.add(" ");
        }
        TableRow tr = new TableRow(this);
        tr.setId(i + 1);
        tr.setOnClickListener(this);
        LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
        TableRow.LayoutParams tr_params = new TableRow.LayoutParams(
                LayoutParams.FILL_PARENT, 155);
        ll.setLayoutParams(tr_params);
        ll.setBackgroundResource(R.drawable.job_match_bg);

        TextView tvBusiness = new TextView(this);
        TextView tvLocation = new TextView(this);
        TextView tvState = new TextView(this);
        TextView tvCompany = new TextView(this);
        img = new ImageView(this);
        TextView tvEmptyText = new TextView(this);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                1000, 1);
        tvEmptyText.setLayoutParams(params);
        //tvEmptyText.setBackgroundResource(R.drawable.line);


        img.setLayoutParams(new TableRow.LayoutParams(28,28));
        //img.setPadding(left, top, right, bottom);
        //img.setId(i*i+2);
        img.setBackgroundResource(R.drawable.starapplied);
        tvCompany.setText("Company:  "
                + XMLfunctions.getValue(e, "company"));
        tvCompany.setTypeface(null, Typeface.BOLD);
        tvCompany.setTextColor(Color.BLACK);
        tvCompany.setPadding(5, 5, 5, 5);

        tvBusiness.setText("Business : " +XMLfunctions.getValue(e, "title"));
        tvBusiness.setTypeface(null, Typeface.BOLD);
        tvBusiness.setTypeface(null, Typeface.BOLD);
        tvBusiness.setTextColor(Color.BLACK);

        tvBusiness.setPadding(5, 5, 5, 5);


        tvState.setText("State:  " + XMLfunctions.getValue(e, "state"));
        tvState.setTypeface(null, Typeface.BOLD);
        tvState.setTextColor(Color.BLACK);

        tvState.setPadding(5, 5, 5, 5);

        tvLocation
                .setText("City:  " + XMLfunctions.getValue(e, "location"));
        tvLocation.setTypeface(null, Typeface.BOLD);
        tvLocation.setTextColor(Color.BLACK);
        tvLocation.setPadding(5, 5, 5, 5);

        img.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
             try
             {
                  AlertDialog.Builder builder = new AlertDialog.Builder(Job_Description.this);
                        builder.setTitle("Save this Job ?");
                       // builder.setMessage("whould You like to save job");
                        builder.setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                         public void onClick(DialogInterface dialog, int which) {
                            // startActivity(new Intent(Job_Description.this,JobSearch.class));
                                img.setBackgroundResource(R.drawable.save);

                             Toast.makeText(getApplicationContext(),"Button Clicked",Toast.LENGTH_LONG).show();
                          Log.e("info", "OK");
                         }
                        });
                        builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int whichButton) {
                                // Canceled.
                                  dialog.cancel();
                              }
                            });
                        builder.show();
             }catch(Exception e)
             {
                 Log.d("Image clicked", e.toString());
             }
            }
        });

        ll.addView(tvCompany);
        ll.addView(tvBusiness);
        ll.addView(img);
        ll.addView(tvState);
        ll.addView(tvLocation);
        ll.addView(tvEmptyText);
       // img.setOnClickListener(this);
        tr.addView(ll);
        tbl.addView(tr);
        // saved job click listener


    }
    mylist = null;
    doc = null;
    nodes = null;
    scv.addView(tbl);


}

对不起英语不好.......

4

1 回答 1

0

你可以直接setimage喜欢

img.setImageResource(R.drawable.apple);

于 2013-11-20T12:15:25.717 回答