我正在从自定义的 mysql 服务器数据库中获取文本ListView
。在自定义列表视图中,我将所有文本附加到 edittext。如何在edittext的内容发生更改时获取edittext值并将其存储在textview上。我想更改edittext值请帮助我
Main.java(here i can pass json array as constructor to EditMainMenulistview.java)
JSONArray json = jArray.getJSONArray("mainmenu");
list=(ListView)findViewById(R.id.mainmenulist);
adapter=new MainMenulist(this, json);
list.setAdapter(adapter);
在这里我可以在 Main.java 中放置按钮更新//按钮
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;
}
}
我在 EditMaiMenulisview 中更改的文本我单击按钮(更新) Main.java 我想打印我在 Edittext 中更改的内容。请重播