【发布时间】:2015-09-27 16:23:30
【问题描述】:
我已经实现了垂直滚动的列表视图,在每一行中都有一个项目,如苹果、柠檬等,这些项目水平滚动。现在我的问题是我需要对选定行中的项目进行排序,并且我需要将结果更新到该行,我无法将值更新到特定行。第一次我将数据从活动加载到适配器并排序值我正在加载适配器类。
这里的代码是..
public static ArrayList<GroupsModel> CustomListViewValuesArr;
public static ArrayList<ItemsModel> ItemsArr;
public MyDisplay_Adapter(Context a, ArrayList d) {
context = a;
data = d;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
if (data.size() <= 0)
return 1;
return data.size();
}
public final Object getItem(int position) {
return data.get(position);
}
public final long getItemId(int position) {
return position;
}
public static class ViewHolder {
public TextView tvGroupTitle, tvGroupDescription,
public LinearLayout imgscrollchild;
}
public View getView(final int position, View convertView, ViewGroup parent) {
Log.d("getview:", "position=" + position);
vi = convertView;
final ViewHolder holder;
if (convertView == null) {
vi = inflater.inflate(R.layout.my_asset_list_item, null);
holder = new ViewHolder();
holder.tvGroupTitle = (TextView) vi.findViewById(R.id.tvGroupTitle);
holder.tvGroupDescription = (TextView) vi
.findViewById(R.id.tvGroupDescription);
holder.imgscrollchild = (LinearLayout) vi
.findViewById(R.id.imgscrollchild);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
if (data.size() <= 0) {
vi.setVisibility(View.GONE);
} else {
tempValues = null;
tempValues = (GroupsModel) data.get(position);
holder.tvGroupTitle.setText(tempValues.getName().toString());
holder.tvGroupDescription.setText(tempValues.getDescription()
.toString());
if (tempValues.getItemmodel().size() == 0) {
return vi;
} else {
for (int i = 0; i < tempValues.getItemmodel().size(); i++) {
a = i;
Log.i("Index", String.valueOf(i));
holder.imgscrollchild.addView(createimg(
tempValues.getItemmodel(), a));
Log.i("Index A", String.valueOf(a));
}
}
}
return vi;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public View createimg(final List<ItemsModel> bm, final int pos) {
Here dynamically creating a imageview and textview
return Hlayout;
}
private class Sort extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
String json = null;
try {
String url_get = "my url"
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url_get);
HttpResponse response = httpclient.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
json = EntityUtils.toString(entity);
try {
JSONArray array = new JSONArray(json);
ItemsArr = new ArrayList<ItemsModel>();
for (int i = 0; i < array.length(); i++) {
JSONObject Obj = array.getJSONObject(i);
String GName = Obj.getString("GName");
String GDesc = Obj.getString("GDesc");
ItemsArr.add(ItemsList);
}
GroupsModel list1 = new GroupsModel();
list1.setItemmodel(ItemsArr);
CustomListViewValuesArr = new ArrayList<GroupsModel>();
CustomListViewValuesArr.add(list1);
} catch (Exception e) {
e.printStackTrace();
Log.e("Exception", e.toString());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
adapter = new MyDisplay_Adapter(context,CustomListViewValuesArr);
adapter.notifyDataSetChanged();
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
【问题讨论】:
-
Here code is..不清楚你问的是什么。 -
我需要对项目进行排序并将排序后的值更新到自定义适配器中的特定行
-
我很困惑如何仅在适配器类中将值更新为适配器
-
I need to sort the items所以,简单地检索它们排序。 -
我得到排序值,但我很困惑如何将其更新到特定行
标签: android json android-listview adapter