繁体   English   中英

更改表格列表视图上的图像android

[英]change image on table list view android

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

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);


}

对不起,英语不好。

你可以直接设置像

img.setImageResource(R.drawable.apple);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM