如何从android中的mysql数据库中获取自定义listview编辑文本中的edittext的所有值

时间:2012-04-10 06:54:39

标签: android android-listview

我从mysql数据库中获取menunames并使用base adapter.now附加到自定义listview中的edittext。我将更改editext值中的一些menunames。现在我想要从头到尾获取所有的文字原型

            Eg:x,y,z,.... are menunames coming from database it append editext(cusom listview)
            i am change editext value y to b
            now i want x,b,z...... values in arraylisst..

我的基础适应性课程

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]);//i append menunames here
        holder.caption.setId(position);
        holder.caption1.setImageBitmap(bmps[position]);

        // we need to update adapter once we finish with editing
        arr.add(holder.caption.getText().toString());//here i am try to get all values change and without edit text values but it get only menunames values

        return convertView;
    }
}

class ViewHolder {
    EditText caption;
    ImageView caption1;
}

class ListItem {
    String caption;
}

请帮帮我

1 个答案:

答案 0 :(得分:0)

我认为您需要OnTouch使用EditText来获取ID,并添加TextWatcher以获取该EditText中的Editext。

以下是EditText中触控侦听器的示例

OnTouchListener mEdittextTouchListener = new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        int childPosition =  v.getId;
        Log.i("Log_tag", "Edittext Position is " + childPosition);
                   //Here you will get your EditText Position.
        //saveData=true;
        //setChildPosition(childPosition);

        return false;
    }
};

现在在您的Activity中实现TextWatcher,并在BaseAdapter的getView中添加如此修改。

 holder.caption.removeTextChangedListener(ExpandableListPage.this);
 holder.caption.setOnTouchListener(mEdittextTouchListener);
 holder.caption.addTextChangedListener(ExpandableListPage.this);

现在确保首先从EditText中删除TextWatcher并添加它。因为当listview视图显示EditText时会调用TextWather方法,为了防止这种情况,我们总是需要删除它然后添加它。

    @Override
public void afterTextChanged(Editable s) {
    Log.v("Log_tag", "After TextChanged" + s.toString());


}

@Override
public void beforeTextChanged(CharSequence s, int start, int count,
        int after) {
    Log.i("Log_tag", "Before TextChanged" + s.toString());

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
    Log.e("Log_tag", "ontext Changed"+ s.toString());
    if(count!=0){
        if(saveData){
            //Add your EditText Change Value here 
                           arr.add(s.toString());
            }
        }

    }


}