Answer the question
In order to leave comments, you need to log in
How to update fragment after AsyncTask called by button in adapter?
UPDATE! The solution advised by Mickey Mouse turned out to be a trick. Firstly, the 8th element of the list may have the position parameter equal to, for example, 1. As I understand it, position is a serial number not in the entire list, but only among the visible elements on the screen. Secondly, at different scrolling speeds, the position value of the same element can be different. For example, if you scroll slowly, then the last element of the list gets position=1, and if you scroll quickly, then position=2. As I understand it, it depends on which already existing list element will be reused for the new one. Ultimately, when processing a button click, the data of the wrong element is retrieved from the arraylist. Tell me how to fix this solution, or how to completely rewrite the processing of buttons so that the correct data is retrieved.
There is one activity. In it, through the NavigationDrawer, fragments with content change. There is one fragment with the list of applications in Listview. Each Listview item contains three buttons.
I process button clicks like this
фрагмент адаптера
--------------------------------
holder.appAccept = (Button) convertView.findViewById(R.id.appAccept);
holder.appAccept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
holder.appEdit = (Button) convertView.findViewById(R.id.appEdit);
holder.appEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
holder.appDelete = (Button) convertView.findViewById(R.id.appDelete);
holder.appDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
whatAction = "delete";
AlertDialog.Builder alertDialog = new AlertDialog.Builder(parent.getContext());
alertDialog.setTitle("Удалить приложение");
alertDialog.setMessage("Вы действительно хотите удалить приложение?");
alertDialog.setPositiveButton("Удалить", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
new AdminDecision(position, whatAction, parent.getContext()).execute();
MySingleton ms = MySingleton.getInstance();
Boolean adminResult = ms.getAdminResult();
String feedInput = ms.getAppsUpdate();
}
});
alertDialog.setNegativeButton("Отмена", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
holder.appIcon.setVisibility(View.INVISIBLE);
}
-------------------------
@Override
protected void onPostExecute(Void aVoid) {
MySingleton ms = MySingleton.getInstance();
ms.setAppsUpdate(jsonFeed.toString());
ms.setAdminResult(adminResult);
}
Answer the question
In order to leave comments, you need to log in
$(document).ready(function(){
for(var i=1;i<=8;i++) {
var text = $("#primtext"+i),
img = $("#prim"+i+" img"),
info = $("#priminfo"+i);
text.hide();
$("#prim"+i).hover(
function(text,img,info){
text.show();
img.hide();
info.css({color: "#50cb10"});
}.bind(null,text,img,info),
function(text,img,info){
text.hide();
img.show();
info.css({color: "#898989"});
}.bind(null,text,img,info)
);
}
});
$(document).ready(function(){
for(var i=1;i<=8;i++) {
$("#primtext"+i).hide();
$("#prim"+i).mouseenter(function(){
$("#primtext"+i).show();
$("#prim"+i+" img").hide();
$("#priminfo"+i).css("color", "#50cb10");
});
$("#prim"+i).mouseleave(function(){
$("#primtext"+i).hide();
$("#prim"+i+" img").show();
$("#priminfo"+i).css("color", "#898989");
});
}
});
You should have data in the adapter, the list of these same applications with which the ListView is filled?
After the AsyncTask completes, you need to remove the "app" from the adapter data and call notifyDataSetChanged.
Solution from MikkiMouse
added to the adapter
private Callbacks callbacks;
public interface Callbacks {
void onAppAccept(int position);
void onAppEdit(int position);
void onAppDelete(int position);
}
public void setCallbacks(Callbacks callbacks) {
this.callbacks = callbacks;
}
holder.appEdit = (Button) convertView.findViewById(R.id.appEdit);
holder.appEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callbacks.onAppEdit(position);
}
});
oneAppAdminAdapter = new OneAppAdminAdapter(AllAppsAdminFragment.this, allAppsList);
oneAppAdminAdapter.setCallbacks(new OneAppAdminAdapter.Callbacks() {
@Override
public void onAppAccept(int position) {
//вызов асинтаска принятия
}
@Override
public void onAppEdit(int position) {
//вызов фрагмента редактирования
}
@Override
public void onAppDelete(int position) {
//вызов асинтаска удаления
}
});
setListAdapter(oneAppAdminAdapter);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question