Trong ứng dụng của tôi, tôi đã sử dụng bộ điều hợp xem danh sách tùy chỉnh. Trong mục xem danh sách, tôi đã thêm một bố cục khác. bởi vì trong một đơn đặt hàng dịch vụ của tôi có bất kỳ số lượng đơn đặt hàng nào. Để hiển thị các mục đặt hàng, tôi đã thêm bố cục mục đặt hàng bên dưới vào mục xem danh sách tùy chỉnh.nó hoạt động tốt. nhưng khi cuộn chế độ xem danh sách, dữ liệu sẽ bị thay đổi.Xem mục danh sách thay đổi vị trí khi di chuyển android?
bộ chuyển đổi lớp:
public class PreviousDataAdapter extends BaseAdapter {
ArrayList<PreviousOrderData> bpData;
private ArrayList<PreviousOrderData> arraylist;
ArrayList<OrderItemData> opData;
private ArrayList<OrderItemData> arraylist1;
private Activity activity;
private LayoutInflater inflater;
String g_orderid;
DatabaseHandler db;
SharedPreferences m_sharedPreference;
SharedPreferences.Editor m_editor;
ArrayList<String> circless = new ArrayList<String>();
public PreviousDataAdapter(Activity activity, ArrayList<PreviousOrderData> bpData,ArrayList<OrderItemData> opdata) {
// TODO Auto-generated constructor stub
this.activity = activity;
this.bpData = bpData;
this.opData=opdata;//k?
// this.opData=bpData.get()//opdata;
inflater = LayoutInflater.from(activity);
db = new DatabaseHandler(activity);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return bpData.size();
}
@Override
public Object getItem(int location) {
// TODO Auto-generated method stub
return bpData.get(location);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
private int lastPosition = -1;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Typeface custom_regular = Typeface.createFromAsset(activity.getAssets(),
"fonts/OpenSans-Regular.ttf");
m_sharedPreference = activity.getSharedPreferences("save_details", activity.MODE_PRIVATE);
m_editor = m_sharedPreference.edit();
//String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
//final View view;
final ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.previousorders_listitem, null);
viewHolder.date = (TextView) convertView.findViewById(R.id.date);
viewHolder.orderid = (TextView) convertView.findViewById(R.id.orderid);
viewHolder.amount = (TextView) convertView.findViewById(R.id.amount);
viewHolder.status = (TextView) convertView.findViewById(R.id.status);
viewHolder.ordersinfo=(LinearLayout)convertView.findViewById(R.id.previousorders);
viewHolder.date .setTypeface(custom_regular);
viewHolder.orderid.setTypeface(custom_regular);
viewHolder.amount.setTypeface(custom_regular);
viewHolder.status.setTypeface(custom_regular);
viewHolder.ll_individuvalitem = (LinearLayout) convertView.findViewById(R.id.ll_individuvalitem);
//convertView = view;
convertView.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.date.setText(bpData.get(position).getDate());
viewHolder.orderid.setText(bpData.get(position).getOrdername());
viewHolder. amount.setText("Rs."+bpData.get(position).getAmount());
viewHolder. status.setText(bpData.get(position).getStatus());
viewHolder.ordersinfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
g_orderid =bpData.get(position).getOrderid();
Log.v("TAG_ORDERIDADAPTER",""+g_orderid);
new GetReorder().execute(WebUrl.RechargeServiceURL+"APP_Reorder");
}
});
//Log.d("size:",opData.size()+"");
if(opData!= null && opData.size() >0){opData.clear();}
opData = bpData.get(position).getOrderItemDataList();//
if(opData.size()>0){
viewHolder.ll_individuvalitem.removeAllViews();
for (int i = 0; i < opData.size(); i++){
// Log.v("TAG Number loop",""+opData.get(i).getNumber());
View itemview = inflater.inflate(R.layout.previousorders_list_single_items, null);
TextView Number = (TextView)itemview.findViewById(R.id.Number);
TextView RechargeAmount = (TextView)itemview.findViewById(R.id.RechargeAmount);
TextView Rechargestatus = (TextView)itemview.findViewById(R.id.Rechargestatus);
Number.setTypeface(custom_regular);
RechargeAmount.setTypeface(custom_regular);
Rechargestatus.setTypeface(custom_regular);
Number.setText(opData.get(i).getNumber());
RechargeAmount.setText("Rs."+opData.get(i).getRechargeAmount());
Rechargestatus.setText(opData.get(i).getRechargestatus());
viewHolder.ll_individuvalitem.addView(itemview);
}
}
return convertView;
}
class ViewHolder {
TextView date, tx_month, orderid, amount,status;
LinearLayout ll_individuvalitem,ordersinfo;
}
private class GetReorder extends AsyncTask<String, Void, JSONObject> {
/*String mJourneyDate;
public GetData(String pJourneyDate) {
this.mJourneyDate = pJourneyDate;
}*/
@Override
protected void onPreExecute() {
super.onPreExecute();
// pDialog = ProgressDialog.show(getActivity(), "", "");
}
@Override
protected JSONObject doInBackground(String... params) {
String response;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(params[0]);
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4);
nameValuePair.add(new BasicNameValuePair("OrderID", g_orderid));
nameValuePair.add(new BasicNameValuePair("DeviceID", m_sharedPreference.getString("deviceId","")));
nameValuePair.add(new BasicNameValuePair("PlatformID", "3"));
nameValuePair.add(new BasicNameValuePair("UserUniqueID", m_sharedPreference.getString("useruid","")));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePair));
HttpResponse responce = httpclient.execute(httppost);
HttpEntity httpEntity = responce.getEntity();
response = EntityUtils.toString(httpEntity);
Log.d("response is", response);
return new JSONObject(response);
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(JSONObject result) {
String Status;
super.onPostExecute(result);
// Log.v("TAG_RESULT",""+result);
if (result != null) {
try {
Intent intent= new Intent(activity, Payment_Actiivity.class);
intent.putExtra("jsonfrompayment",result.toString());
Log.v("TAG_JSONPAY",""+result.toString());
activity.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
} else {
Toast.makeText(activity, "something went wrong", Toast.LENGTH_LONG).show();
}
}
}
}
không hoạt động đối với tôi –
Tiền phạt hoạt động của nó. Nhưng câu hỏi vẫn còn như thế nào là nó làm việc ?? – Rookie
@Rookie Trên thực tế, các phương pháp này cho hệ thống biết liệu bộ điều hợp có cần tái chế các hàng hay không và cũng có bao nhiêu loại hàng chúng tôi muốn hiển thị. để biết thông tin chi tiết về việc này, hãy truy cập liên kết này: http://stackoverflow.com/a/5301093/4531507 –