- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
请看这个屏幕:
当我点击接受更改为另一个按钮时:
如果我在可扩展 ListView 中单击一个 getChildView
列表项,它也会在滚动屏幕时影响其他子项。在这里,我在单击 getChildview
项时更改了按钮文本
这里我点击了一个 child 的接受按钮,然后它应该变成另一个按钮但是当滚动所有子项目按钮时也会改变
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private final Context context;
private final List<String> headings;
private List<DriverOrders> order;
GroupHolder holder;
public ExpandableListAdapter(final FragmentActivity fragmentActivity,
final List<String> lidtDataHeaders, final List<DriverOrders> orders
) {
this.context = fragmentActivity;
this.headings = lidtDataHeaders;
this.order = orders;
}
@Override
public Object getChild(final int groupPosition, final int childPosition) {
return this.headings.get(childPosition);
}
@Override
public long getChildId(final int groupPosition, final int childPosition) {
return childPosition;
}
@Override
public View getChildView(final int groupPosition,
final int childPosition, final boolean isLastChild,
View convertView, final ViewGroup parent) {
final String childName = (String) getChild(groupPosition, childPosition);
// GroupHolder holder;
holder = null;
if (convertView == null) {
final LayoutInflater inflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.driver_child_layout, null);
holder = new GroupHolder();
holder.orderNumber = (TextView) convertView.findViewById(R.id.orderNumber);
holder.taskType = (TextView) convertView.findViewById(R.id.taskType);
holder.detaisl = (TextView) convertView.findViewById(R.id.detaisl);
holder.accept = (Button) convertView.findViewById(R.id.accpet);
holder.decline = (Button) convertView.findViewById(R.id.decline);
holder.started = (Button) convertView.findViewById(R.id.started);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
/* TextView orderNumber = (TextView) convertView.findViewById(R.id.orderNumber);
TextView taskType = (TextView) convertView.findViewById(R.id.taskType);
TextView detaisl = (TextView) convertView.findViewById(R.id.detaisl);
accept = (Button) convertView.findViewById(R.id.button);
decline = (Button) convertView.findViewById(R.id.decline);
started = (Button) convertView.findViewById(R.id.started);*/
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("","inside convertview click"+parent.getChildAt(childPosition));
}
});
holder.started.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (flag) {
AsyncHttpClient client = new AsyncHttpClient();
client.get(null, CommonUtility.SERVER_URI + "person-started/" + Long.parseLong(order.get(groupPosition).getOrderId().trim()), new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
try {
if (response.getString("STATUS").equalsIgnoreCase("true")) {
mListener.onStarttrip(order.get(groupPosition).getOrderId(), order.get(groupPosition).getCustomerName(), order.get(groupPosition).getCustomerContact());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
if (statusCode == 404) {
Toast.makeText(getActivity(), "Requested resource not found", Toast.LENGTH_LONG).show();
}
// When Http response code is '500'
else if (statusCode == 500) {
Toast.makeText(getActivity(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}
// When Http response code other than 404, 500
else {
Toast.makeText(getActivity(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
}
}
});
} else {
Toast.makeText(getActivity(), "Before started you have to accept the order", Toast.LENGTH_LONG).show();
}
}
});
holder.orderNumber.setText(order.get(groupPosition).getCustomerName());
holder.taskType.setText(order.get(groupPosition).getCustomerContact());
holder.detaisl.setText(order.get(groupPosition).getOrderId());
holder.accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e("", "group positioins" + groupPosition);
String associateId = sessionManager.getUserDetails().get("associate_id");
String oredeerid = order.get(groupPosition).getOrderId();
RequestParams params = new RequestParams();
params.put("oid", oredeerid);
params.put("did", associateId);
requestForAcceptOrder(params, groupPosition);
}
});
holder.decline.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
holder.decline.setFocusable(false);
holder.decline.setEnabled(false);
holder.decline.setClickable(false);
sessionManager.setDclineId(order.get(groupPosition).getOrderId());
Toast.makeText(getActivity(), "Order is declined", Toast.LENGTH_LONG).show();
Intent myIntent = new Intent(getActivity(), DeclineReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, myIntent, 0);
Long timeInMillis = new GregorianCalendar().getTimeInMillis() + 1000;
Log.d("pass", "!!!!!!!");
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, timeInMillis, 5400000, pendingIntent);
notifyDataSetChanged();
}
});
return convertView;
}
@Override
public int getChildrenCount(final int groupPosition) {
return 1;
}
@Override
public Object getGroup(final int groupPosition) {
return this.headings.get(groupPosition);
}
@Override
public int getGroupCount() {
return this.headings.size();
}
@Override
public long getGroupId(final int groupPosition) {
return groupPosition;
}
@SuppressLint("NewApi")
@Override
public View getGroupView(final int groupPosition,
final boolean isExpanded, View convertView,
final ViewGroup parent) {
final String headerTitle = (String) this.getGroup(groupPosition);
/* final ExpandableListView mExpandableListView = (ExpandableListView) parent;
mExpandableListView.expandGroup(0);*/
// to display indicator of Expandable view from left to right
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
CabOrderFragment.this.expnListView
.setIndicatorBounds(
CabOrderFragment.this.expnListView
.getWidth() - 50,
CabOrderFragment.this.expnListView
.getWidth());
} else {
CabOrderFragment.this.expnListView
.setIndicatorBoundsRelative(
CabOrderFragment.this.expnListView
.getWidth() - 50,
CabOrderFragment.this.expnListView
.getWidth());
}
final LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(
R.layout.expandlistview_heading_group, null);
// final ImageView image = (ImageView) convertView
// .findViewById(R.id.ivHeadeImage);
final TextView lblListHeader = (TextView) convertView
.findViewById(R.id.tvListHeader);
// image.setImageResource(this.images[groupPosition]);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle.toUpperCase(Locale.getDefault()));
lblListHeader.setTextSize(10);
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(final int groupPosition,
final int childPosition) {
// TODO Auto-generated method stub
return true;
}
private void requestForAcceptOrder(RequestParams params, final int groupPosition) {
AsyncHttpClient client = new AsyncHttpClient();
client.get(null, CommonUtility.SERVER_URI + "accept", params, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject obj) {
try {
if (obj.getInt("code") == 0) {
holder.accept.setVisibility(View.GONE);
holder.decline.setVisibility(View.INVISIBLE);
holder.started.setVisibility(View.VISIBLE);
Toast.makeText(getActivity(), "Oeder is Placed", Toast.LENGTH_LONG);
Intent myIntent = new Intent(getActivity(), DriverOrdersReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, myIntent, 0);
Log.d("stop alarm", "!!!!!!!");
AlarmManager alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
flag = true;
Log.e("", "object data" + obj.toString());
} else {
Toast.makeText(getActivity(), "Oeder is Not Placed", Toast.LENGTH_LONG);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
if (statusCode == 404) {
Toast.makeText(getActivity(), "Requested resource not found", Toast.LENGTH_LONG).show();
}
// When Http response code is '500'
else if (statusCode == 500) {
Toast.makeText(getActivity(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
}
// When Http response code other than 404, 500
else {
Toast.makeText(getActivity(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet or remote server is not up and running]", Toast.LENGTH_LONG).show();
}
}
});
}
/*private view holder class*/
private class GroupHolder {
TextView orderNumber;
TextView taskType;
TextView detaisl;
Button accept;
Button decline;
Button started;
}
}
最佳答案
您的问题是由于 Recycling mechanism 引起的,您需要在 getChildView()
方法中重置文本颜色。
这可以通过 if{}else{}
案例来完成。
例如:
if(yourTextMustTakeTheDefaultColor){
// set the default color in your text
} else {
// set the other color
}
更新:
1)首先不要使用holder作为类变量。
从您的适配器中删除类变量 GroupHolder holder;
。
然后像这样更改您的 getChildView()
代码:
GroupHolder holder;
if (convertView == null) {
final LayoutInflater inflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.driver_child_layout, null);
holder = new GroupHolder();
//the rest of code...
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
//the rest of code...
2) 就像我已经告诉你的那样:在 getChildView()
中添加 if else
案例来更新你的 View (我想你想更新 accept/下降/开始可见性)取决于子数据。
例如:
if(order.get(groupPosition).isAcceptedVisible()){
holder.accept.setVisibility(View.VISIBLE);
} else {
holder.accept.setVisibility(View.GONE);
}
3) 更改您的 requestForAcceptOrder()
以传递子位置。
private void requestForAcceptOrder(RequestParams params, final int groupPosition, final int childPosition)
4) 在 onSuccess()
方法中,您有 groupPosition
和 childPosition
,更新您的列表的数据/模型并调用 notifyDataSetChanged ();
,系统将负责更新您的 View 。
关于java - getChild 查看项目 onClickListener 正在影响 ExpandableListView Android 中的所有子项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33603030/
当我单击图像时,它不会更改显示 TextView ,我哪里出错了? **List fields = new ArrayList(); for(int i = 0; i < 64; i+
我想做的是提供一个平台列表供用户选择。通过单击一个平台,它会将相应的 sql 表名称的名称放入变量中。但我不知道如何在我的提交按钮 clickListener 中使用该变量。这是我正在使用的代码部分。
我可以在我的 recyclerView holder 中实现它们 public class PagosPendientesViewHolder extends RecyclerView.ViewHol
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
当我想向 setOnClickListener 添加参数(例如按钮)时,我从 eclipse 警报中单击 View.OnClickListener() ,但 eclipse 类型 new OnClic
我看了http://developer.android.com/reference/android/view/package-summary.html并看到 View 类有一个名为“View.OnCl
我正在尝试 android 上的示例应用程序。我可以获得输出。 studentFormsActiviyt.java package com.example.android.accelerometerp
我有一个关于实现 OnClickListeners 以使用 ADT 进行开发的问题。我不确定哪种方法更有效,谁能告诉我每种方法的优缺点? class x extends Activity implem
我要问一个非常基本的问题,但我被困了很长时间。 在卡片 View 之后有一个回收 View ,每行有 2 个图像。现在我想在图像上创建点击监听器而不是 recycleview。 这个 Activity
我的理解是,当我创建一个监听点击的按钮对象时,我必须: 创建按钮对象 使用OnClickListner让它监听用户的点击 使用onClick在用户点击按钮后执行 Action 现在, setOnCli
我正在学习 android 开发的初学者教程,但我不明白这个错误。 错误在行“callButton.setOnClickListener(new OnClickListener() {” 是的,我知道
当使用下面的代码时,我不断收到错误,我知道还有另一种使用 onclick 函数的方法,android:onclick ...但我更喜欢这种“更清洁”的方式。 textview 的 id 名称是正确的,
尝试将 onClickListener 添加到我的 listView 中的项目时,我收到一条错误消息:“View 类型中的方法 setOnClickListener(View.OnClickListe
我有一个问题...我有不同的 TextView 和一个监听器。像这些: help_modul.setOnClickListener(this); help_timetable.setO
我创建了一个自定义的 AutocompleteAdapter,我需要允许用户选择某个对象(客户)。 我的 AutoCompleteAdapter 看起来像这样: package nl.raakict.
我有一个程序,它有一个用户可以编辑的文本框。当用户按下按钮时,会创建一个对话框,显示用户的文本和确认“是/否”选项。 public void setIP(View v){ //get the
这个问题在这里已经有了答案: NullPointerException accessing views in onCreate() (13 个回答) What is a NullPointerExce
我有一个自定义 View ,我想当我设置 onClickListener 时我总是会崩溃。 public class Holder extends View implements OnClickLis
我有一组复选框,它们都需要 OnClickListener 来查看它们何时被选中/取消选中。这是我所拥有的: CheckBox[] sens = new CheckBox[3]; for (int i
我有两个简单的不同类,其中一个类扩展了另一个类。我的第一个类是: public class MyObject {} 里面没有任何东西。 还有另一个: public class People exten
我是一名优秀的程序员,十分优秀!