ich ein Listview erstellt habe ein Layout aufpumpen. Das aufgeblähte Layout hat einen Editiertext und zwei Buttons, die den Wert in editiertext erhöhen oder verringern. Aber das Problem ist, wenn ich den Wert des ersten editedtext in listview ändere, werden die Änderungen im vierten edittext (viertes child item) von listview widergespiegelt. In ähnlicher Weise spiegeln sich die Änderungen im zweiten Bearbeitungstext zum fünften Bearbeitungstext und so weiter. Der Code, den ich geschrieben habe, um Layouts in Listenansicht aufzublasen, ist wie folgt. Bitte helfen Sie mir, das Problem zu lösen.Änderung eines Kind Layout Listview in anderer Listenansicht Kind reflektierende Layouts
public class DisplayList extends AppCompatActivity {
private static final String TAG_CATEGORY = "main_name";
private static final String TAG_SUBCAT = "cat_name";
private static final String TAG_CODE = "code";
private static final String TAG_NAME = "name";
private static final String TAG_RATE = "rate";
private static final String TAG_RATE2 = "rate2";
private static final String TAG_RATE3 = "rate3";
private static final String TAG_IMAGE = "img";
ImageAdapter mImageAdapter = null;
ListView mListView = null;
DatabaseHelper myDb;
FloatingActionButton fab1;
public ArrayList<DetailsVO> mListDetails = new ArrayList<DetailsVO>();
String subc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_list);
myDb=new DatabaseHelper(DisplayList.this);
fab1 = (FloatingActionButton) findViewById(R.id.fab);
fab1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(DisplayList.this,NewCart.class);
startActivity(intent);
}
});
mListView = (ListView) findViewById(R.id.list_view);
Bundle extras = getIntent().getExtras();
if (extras != null) {
subc = extras.getString("Subcat");
}
new AsyncCallSoap1().execute();
}
public class AsyncCallSoap1 extends AsyncTask<String,Void,String> {
private final ProgressDialog dialog=new ProgressDialog(DisplayList.this);
@Override
protected String doInBackground(String... params) {
CallSoap com=new CallSoap();
String SOAP_ACTION="http://tempuri.org/IprotechService/SelectSuCatgeory";
String OPERATION_NAME="SelectSuCatgeory";
String response = com.getDetails(OPERATION_NAME,SOAP_ACTION);
if(response!=null){
try {
JSONArray array1 = new JSONArray(response);
for(int i=0;i<array1.length();i++)
{
final DetailsVO detailsVO = new DetailsVO();
JSONObject obj1 = array1.getJSONObject(i);
String out_category = obj1.getString(TAG_CATEGORY);
String out_subcat = obj1.getString(TAG_SUBCAT);
String out_code = obj1.getString(TAG_CODE);
String out_name = obj1.getString(TAG_NAME);
String out_rate = obj1.getString(TAG_RATE);
String out_rate2 = obj1.getString(TAG_RATE2);
String out_rate3 = obj1.getString(TAG_RATE3);
String out_img = obj1.getString(TAG_IMAGE);
if(subc.equalsIgnoreCase(out_subcat)){
detailsVO.setImage(out_img);
detailsVO.setName(out_name);
detailsVO.setRate(out_rate);
detailsVO.setRate2(out_rate2);
detailsVO.setRate3(out_rate3);
mListDetails.add(detailsVO);}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return response;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
//Showing progress dialog
dialog.setMessage("Please wait...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
dialog.dismiss();
if(mListDetails != null){
mImageAdapter = new ImageAdapter(DisplayList.this, mListDetails);
mListView.setAdapter(mImageAdapter);
}
}
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<DetailsVO> mItems;
private ArrayList<DetailsVO> mOriginalItems;
public ImageAdapter(Context context, ArrayList<DetailsVO> items) {
this.mContext = context;
this.mItems = items;
}
@Override
public int getCount() {
return mItems.size();
}
@Override
public DetailsVO getItem(int position) {
return mItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public ArrayList<DetailsVO> getItems(){
return mItems;
}
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.row_layout, null);
}
DetailsVO detailsVO = mItems.get(position);
View listView = (View) convertView;
ImageView image = (ImageView) listView.findViewById(R.id.imageView2);
final TextView textTitle = (TextView) listView.findViewById(R.id.textView2);
final Spinner spinner=(Spinner) listView.findViewById(R.id.spinner);
Button btnplus = (Button) listView.findViewById(R.id.max);
Button btnminus = (Button) listView.findViewById(R.id.min);
final Button btnadd=(Button) listView.findViewById(R.id.btn_add);
btnadd.setClickable(true);
final TextView quantity = (TextView) listView.findViewById(R.id.quantity);
ArrayList<String> rate=new ArrayList<String>();
rate.add("Rs."+detailsVO.getRate());
if(detailsVO.getRate2()!= null && !detailsVO.getRate2().isEmpty())
{
rate.add("Rs."+detailsVO.getRate2());
}
if(detailsVO.getRate3()!= null && !detailsVO.getRate3().isEmpty())
{
rate.add("Rs."+detailsVO.getRate3());
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(DisplayList.this, android.R.layout.simple_spinner_item,rate);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(dataAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String item = parent.getItemAtPosition(position).toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
btnminus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String value = quantity.getText().toString();
int quantity1 = Integer.parseInt(value);
if(quantity1>0)
{
quantity1 = quantity1 -1;
String t = Integer.toString(quantity1);
quantity.setText(t);
}
}
});
btnplus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String value1 = quantity.getText().toString();
int quantity2 = Integer.parseInt(value1);
quantity2 = quantity2 + 1;
String t=Integer.toString(quantity2);
quantity.setText(t);
}
});
final String u=detailsVO.getImage();
btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String im="http://protech.absoftwaresolution.com/img/grocery_imgs/grains/"+u;
String nm = textTitle.getText().toString();
String value = quantity.getText().toString();
int q= Integer.parseInt(value);
String rate=spinner.getSelectedItem().toString();
String val = rate.substring(rate.lastIndexOf("-")- 1);
final String val1=rate.substring(3,rate.lastIndexOf("-"));
int b = Integer.parseInt(val1.trim());
final int a= q*b;
String c=Integer.toString(a);
boolean isInserted = myDb.insertData(im,nm,val1,q,a);
if (isInserted == true) {
Toast.makeText(DisplayList.this, "Item Added Successfully!!!", Toast.LENGTH_LONG).show();
}
}
});
Picasso.with(mContext)
.load("http://protech.absoftwaresolution.com/img/grocery_imgs/grains/"+detailsVO.getImage())
.placeholder(R.drawable.placeholder)
.into(image);
textTitle.setText(detailsVO.getName());
return listView;
}
}
Wenn ich auf btnplus & btnminus I EditText Wert am Wechsel, die
Verwenden _View Holder_ Muster-Set ... werden! – Piyush
Ok, danke, ich werde versuchen –