0
        listview
       jArray = new JSONObject(result);
         json = jArray.getJSONArray("mainmenu");
        list = (ListView) findViewById(R.id.mainmenulist);
        adapter = new EditMainMenulistview(this, json);
        list.setAdapter(adapter);
         EditMainMenulistview

        public class EditMainMenulistview extends BaseAdapter {
public final ArrayList<String> arr=new ArrayList<String>();
protected static Context Context = null;
int i;
public String editnewmainmenu, menuname,edittext;
String qrimage;
Bitmap bmp, resizedbitmap;
Bitmap[] bmps;
Activity activity = null;
private LayoutInflater inflater;

private ImageView[] mImages;
String[] itemimage;
TextView[] tv;
String itemname, itemcode;
public String[] itemnames, itemcodes;
HashMap<String, String> map = new HashMap<String, String>();

public EditMainMenulistview(Context context, JSONArray imageArrayJson) {
    Context = context;
    // inflater =
    // (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // imageLoader=new ImageLoader(activity);
    inflater = LayoutInflater.from(context);
    this.mImages = new ImageView[imageArrayJson.length()];
    this.bmps = new Bitmap[imageArrayJson.length()];
    this.itemnames = new String[imageArrayJson.length()];
    this.itemcodes = new String[imageArrayJson.length()];

    try {

        for (i = 0; i < imageArrayJson.length(); i++) {
            JSONObject image = imageArrayJson.getJSONObject(i);
            qrimage = image.getString("menuimage");
            itemname = image.getString("menuname");
            itemcode = image.getString("menucode");
            itemnames[i] = itemname;
            itemcodes[i] = itemcode;

            byte[] qrimageBytes = Base64.decode(qrimage.getBytes());

            bmp = BitmapFactory.decodeByteArray(qrimageBytes, 0,
                    qrimageBytes.length);
            int width = 100;
            int height = 100;
            resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height,
                    true);
            bmps[i] = bmp;

            mImages[i] = new ImageView(context);
            mImages[i].setImageBitmap(resizedbitmap);

            mImages[i].setScaleType(ImageView.ScaleType.FIT_START);

            // tv[i].setText(itemname);
        }
        System.out.println(itemnames[i]);


    } catch (Exception e) {
        // TODO: handle exception
    }
}

public int getCount() {
    return mImages.length;
}

public Object getItem(int position) {
    return position;
}

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

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


    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.editmainmenulist, null);
        holder.caption = (EditText) convertView
                .findViewById(R.id.editmaimenu);
        holder.caption1=(ImageView) convertView.findViewById(R.id.menuimage);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    //Fill EditText with the value you have in data source
    holder.caption.setText(itemnames[position]);
    holder.caption.setId(position);
    holder.caption1.setImageBitmap(bmps[position]);

    //we need to update adapter once we finish with editing
    holder.caption.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus)
        {
                final int position = v.getId();
                final EditText Caption = (EditText) v;

                holder.caption.setFocusable(true);

                arr.add(holder.caption.getText().toString());


        }
            }

    });  



    return convertView;
}
 }

     class ViewHolder {
EditText caption;
ImageView caption1;
    }

     class ListItem {
String caption;
 }

如果我可以更改所有 ediitext 值并发送到 mysql 数据库,我可以替换旧的菜单名称。如果我无法更新 2 个菜单名称..请告诉我.................................................. ………………………………………………………………………………

4

1 回答 1

0

使用getText()方法..获取所有这些值,然后更新您的数据库(但我认为这不是您要查找的内容...但您的问题尚不清楚)..

这是您需要遵循的步骤..

使用findViewByID()获取所有编辑文本的引用,然后使用 getText 方法获取所有这些文本,然后使用这些值更新数据库。

代替 ArrayList 使用 HashMap.. 并在您的代码中进行这些更改..

public class EditMainMenulistview extends BaseAdapter {
public final HashMap<String, String> arr=new HashMap<String, String>;
protected static Context Context = null;
int i;
public String editnewmainmenu, menuname,edittext;
String qrimage;
Bitmap bmp, resizedbitmap;
Bitmap[] bmps;
Activity activity = null;
private LayoutInflater inflater;

private ImageView[] mImages;
String[] itemimage;
TextView[] tv;
String itemname, itemcode;
public String[] itemnames, itemcodes;
HashMap<String, String> map = new HashMap<String, String>();

public EditMainMenulistview(Context context, JSONArray imageArrayJson) {
    Context = context;
    // inflater =
    // (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // imageLoader=new ImageLoader(activity);
    inflater = LayoutInflater.from(context);
    this.mImages = new ImageView[imageArrayJson.length()];
    this.bmps = new Bitmap[imageArrayJson.length()];
    this.itemnames = new String[imageArrayJson.length()];
    this.itemcodes = new String[imageArrayJson.length()];

    try {

        for (i = 0; i < imageArrayJson.length(); i++) {
            JSONObject image = imageArrayJson.getJSONObject(i);
            qrimage = image.getString("menuimage");
            itemname = image.getString("menuname");
            itemcode = image.getString("menucode");
            itemnames[i] = itemname;
            itemcodes[i] = itemcode;

            byte[] qrimageBytes = Base64.decode(qrimage.getBytes());

            bmp = BitmapFactory.decodeByteArray(qrimageBytes, 0,
                    qrimageBytes.length);
            int width = 100;
            int height = 100;
            resizedbitmap = Bitmap.createScaledBitmap(bmp, width, height,
                    true);
            bmps[i] = bmp;

            mImages[i] = new ImageView(context);
            mImages[i].setImageBitmap(resizedbitmap);

            mImages[i].setScaleType(ImageView.ScaleType.FIT_START);

            // tv[i].setText(itemname);
        }
        System.out.println(itemnames[i]);


    } catch (Exception e) {
        // TODO: handle exception
    }
}

public int getCount() {
    return mImages.length;
}

public Object getItem(int position) {
    return position;
}

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

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


    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.editmainmenulist, null);
        holder.caption = (EditText) convertView
                .findViewById(R.id.editmaimenu);
        holder.caption1=(ImageView) convertView.findViewById(R.id.menuimage);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    //Fill EditText with the value you have in data source
    holder.caption.setText(itemnames[position]);
    holder.caption.setId(position);
    arr.add(position,itemnames[position]);
    holder.caption1.setImageBitmap(bmps[position]);

    //we need to update adapter once we finish with editing
    holder.caption.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
        if(!hasFocus)
        {
                final int position = v.getId();
                final EditText Caption = (EditText) v;

                holder.caption.setFocusable(true);
                arr.remove(holder.caption.getId());
                arr.add(holder.caption.getId(),holder.caption.getText().toString());


        }
            }

    });  



    return convertView;
}
 }

     class ViewHolder {
EditText caption;
ImageView caption1;
    }

     class ListItem {
String caption;
 }
于 2012-04-11T03:52:51.143 回答