我从数据库中获取文本并附加到编辑text.it显示edittext.now中的所有文本我正在更改editext中的一些文本。我希望我在editext中更改了我希望打印的值
this my listview code
JSONArray json = jArray.getJSONArray("mainmenu");
list = (ListView) findViewById(R.id.mainmenulist);
adapter = new EditMainMenulistview(this, json);
list.setAdapter(adapter);(here i can pass json array to EditMainMenulistview.java)
Menuoption
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.text:
String gou=adapter.edittext.toString();//here only i want print all editext names i can change
System.out.println(gou);
break;
default:
break;
}
return true;
}
EditMainMenulistview.java
public class EditMainMenulistview extends BaseAdapter {
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]);
System.out.println(map);
} 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(final int position, View convertView, ViewGroup parent) {
View vi = convertView;
vi = inflater.inflate(R.layout.editmainmenulist, null);
EditText text = (EditText) vi.findViewById(R.id.editmaimenu);
ImageView image = (ImageView) vi.findViewById(R.id.menuimage);
image.setImageBitmap(bmps[position]);
text.append(itemnames[position]);
edittext = text.getText().toString();
System.out.println(edittext);
//Toast.makeText(Context, edittext, Toast.LENGTH_LONG).show();
return vi;
}
}
上面的鳕鱼我可以附加所有数据库项目名来编辑text.now我可以更改编辑文本中的一些项目名称。我更改了项目名称我单击菜单选项它打印所有更改的编辑文本值
答案 0 :(得分:0)
我不确定你真正想要的是什么。
如何从edittext自定义列表视图中获取可编辑的更改值并存储在android
中的数组中View vi = convertView; vi = inflater.inflate(R.layout.editmainmenulist, null); EditText text = (EditText) vi.findViewById(R.id.editmaimenu); text.append(itemnames[position]);//here i append so many itemnames append to edittext
调用此方法是为了在 s 中通知您 count 个字符 从 start 开始,刚刚替换了之前长度的旧文本。
mEditText.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } });