In my application I have draft messages which I can edit. Some of my drafts include attachments which I try to send to my edit activity and show it at recyclerview. In general I have managed to send my string arraylist and get it at my activity. But I can't show my attached files, especially their names at the recyclerview. I tried to make smth like that:
adapter.notifyDataSetChanged();
but it didn't help me.
So, firstly I get from my message names of attached files:
file_name = Objects.requireNonNull(response.body()).getAttachesNames();
then put this names into arraylist:
nameList = new ArrayList<>(Arrays.asList(file_name));
such result I can see in my logs:
W: [eZV9f.jpg, index.html]
and then I send my list via intent to another activity:
intent2.putStringArrayListExtra("attached_files", (ArrayList<String>) nameList);
receiving data from intent:
Intent intent = getIntent();
extras = intent.getExtras();
if (extras != null) {
if (extras.containsKey("attached_files")) {
draft_files = getIntent().getStringArrayListExtra("attached_files");
Log.w("MY_TAG", String.valueOf(draft_files));
}
}
results from logcat:
W: [eZV9f.jpg, index.html]
initialising of my adapter and recyclerview:
adapter = new AttachedFileAdapter(mNames);
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(WriteResponseMess.this, LinearLayoutManager.VERTICAL, false));
and then I try to get single element from this list and add to my ArrayList<>:
for (int i = 0; i < draft_files.size(); i++) {
mNames.addAll(Collections.singleton(draft_files.get(i)));
adapter.notifyDataSetChanged();
recyclerView.setAdapter(adapter);
Log.w("MY_TAG", draft_files.get(i));
Log.w("MY_TAG", String.valueOf(mNames));
}
all previous pieces of code are used at my onCreate() method and as a result of all these actions I would like to see income data from another activity. Sometimes I managed to do it, but one element contained all income data and looked like this:
[eZV9f.jpg, index.html]
and it was wrong for me. I try to create the list which will contain all elements separately. I also tried to use some info from this link which is connected with Collections, but I didn't manage to reach the goal of my task. In general I'm sure that the solution is very simple but I can't see it.
update
all my activity class has more than 1000 lines and I will share all code which is connected with adding attachments and show attached data at my writing form:
Here is my dialog for getting directory list and choosing some files:
#Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case CUSTOM_DIALOG_ID:
dialog = new Dialog(WriteResponseMess.this, android.R.style.Theme_DeviceDefault_Light_NoActionBar_Fullscreen);
dialog.setContentView(R.layout.dialog_layout);
dialog.setCanceledOnTouchOutside(true);
Toolbar toolbar = dialog.findViewById(R.id.toolbar_d);
toolbar.setTitle("Add a new file.");
textFolder = dialog.findViewById(R.id.folder);
buttonUp = dialog.findViewById(R.id.up);
buttonUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ListDir(curFolder.getParentFile());
}
});
dialog_ListView = dialog.findViewById(R.id.dialoglist);
final Dialog finalDialog1 = dialog;
dialog_ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#RequiresApi(api = Build.VERSION_CODES.O)
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
File selected = new File(curFolder, fileList.get(position));
if (selected.isDirectory()) {
ListDir(selected);
}
if (selected.isFile()) {
if (array.size() == 0) {
array = uploadFiles(array, selected.getName(), convertFileToString(selected.getPath()));
adapter.notifyDataSetChanged();
getImages();
} else {
if (array.toString().contains(selected.getName())) {
Toast.makeText(WriteResponseMess.this, R.string.attaching_message, Toast.LENGTH_SHORT).show();
adapter.notifyDataSetChanged();
getImages();
} else {
array = uploadFiles(array, selected.getName(), convertFileToString(selected.getPath()));
adapter.notifyDataSetChanged();
getImages();
}
}
finalDialog1.dismiss();
ms.setArray(array);
}
}
});
break;
}
return dialog;
}
and method for showing attached list, and in general this method works when I create a new message and attach a new file, it works fine:
private void getImages() {
mNames.clear();
adapter.notifyDataSetChanged();
for (int i = 0; i < array.size(); i++) {
JsonObject object = array.get(i).getAsJsonObject();
if (extras != null) {
if (extras.containsKey("attached_files")) {
for (int j = 0; j < draft_files.size(); j++) {
mNames.clear();
mNames.add(draft_files.get(j));
adapter.notifyDataSetChanged();
//Log.w("MY_TAG", draft_files.get(i));
Log.w("MY_TAG", String.valueOf(mNames));
}
mNames.add(object.get("filename").toString().substring(1, object.get("filename").toString().length() - 1));
adapter.notifyDataSetChanged();
//Log.w("MY_TAG", Arrays.toString(draft_files));
Log.w("MY_TAG", Arrays.toString(new ArrayList[]{mNames}));
} else {
mNames.add(object.get("filename").toString().substring(1, object.get("filename").toString().length() - 1));
adapter.notifyDataSetChanged();
Log.w("MY_TAG", String.valueOf(mNames));
}
}
}
}
no need to set Adapter twice . remove this line
recyclerView.setAdapter(adapter);
From
for (int i = 0; i < draft_files.size(); i++) {
mNames.addAll(Collections.singleton(draft_files.get(i)));
adapter.notifyDataSetChanged();
//recyclerView.setAdapter(adapter); no need
Log.w("MY_TAG", draft_files.get(i));
Log.w("MY_TAG", String.valueOf(mNames));
}
Related
I have one custom dialogue in my application which have not any issue. Its working fine but I am getting white space above my dialogue like this image.
I am facing issue only device which have Lollipop and lower API. My code is looking like below
private void showGotoPageDialog() {
if (getActivity() != null) {
if (mPageOptions.length == 0)
return;
final Dialog mDialog = new Dialog(getActivity());
mDialog.setContentView(R.layout.grid_dialogue);
if(mDialog.getWindow()!=null){
mDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);}
GridView mGridView = mDialog.findViewById(R.id.grid_dialog);
ArrayList<String> tmp = new ArrayList<>(mPageOptions.length);
for (int i = 0; i < mPageOptions.length; i++) {
tmp.add(mPageOptions[i].split(" ")[1]);
}
final CustomAdapter adapter = new CustomAdapter(getActivity(), tmp, mPageIndx);
mGridView.setAdapter(adapter);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int item, long l) {
adapter.a.cancel();
mDialog.dismiss();
mPageIndx = item + 1;
updateQuotesList();
updatePageInfo();
}
});
mDialog.show();
TextView dismiss =mDialog.findViewById(R.id.dialog_dismiss);
dismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
adapter.a.cancel();
mDialog.dismiss();
}
});
}
}
Let me know if someone have idea to fix it. Thanks
White Space Above Dialogue in Lollipop Device
it is called Dialog Title
Try this use mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); it will remove the Blank title space from your Dialog
Sample code
final Dialog mDialog = new Dialog(getActivity());
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.grid_dialogue);
mDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);}
GridView mGridView = mDialog.findViewById(R.id.grid_dialog);
// your whole dialog code
i'm trying to download a list of cases from a server and then populate an arraylist to use it in my RecyclerView Adapter but every time i try to populate the array list from asynctask i can print the data in every single step from the populating bu not from the Arraylist i'm using (i'm trying to store in an arrayList that contains objects of the type Case which i created)
this is the part of the code with the problem
this is my AsyncTask...
`
public class downloadingNewCases extends AsyncTask<Void,Void ,Boolean>{
private String userid ;
private String state ;
public downloadingNewCases(String userid ,String state ){
this.userid = userid ;
this.state = state ;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
Log.d(AppController.DEBUG, "download New Cases Started");
}
#Override
protected Boolean doInBackground(Void... params){
Log.d(AppController.DEBUG , "user id in the get cases link.." + userid);
String url = AppController.ApiUrl + "GetCases?UserName="+ userid +"&stat="+state;
Log.d(AppController.DEBUG_LINK,url);
try {
JsonArrayRequest request = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Log.d("TEST", String.valueOf(response.length()));
for (int i = 0; i < response.length(); i++) {
try {
Log.d("TEST","downloading data" );
JSONObject object = response.getJSONObject(i);
JSONArray specs = object.getJSONArray("Spe");
ArrayList<Specialities> spe = new ArrayList<>();
for (int j = 0; j < specs.length(); j++) {
Log.d("TEST",specs.getJSONObject(j).getString("SName") );
spe.add(new Specialities(null, specs.getJSONObject(j).getString("SName")));
}
Case ca = new Case(object.getString("ID")
, object.getString("Serial")
, object.getString("Name")
, object.getString("gender")
, object.getString("Age")
, object.getString("NatioanlityID")
, object.getString("HealthProblem")
, object.getString("CityID")
, object.getString("Problem")
, object.getString("Date")
, object.getString("Status")
, spe);
Log.d("TEST",ca.toString());
cases.add(ca);
spe.clear();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
Log.d(AppController.DEBUG , volleyError.toString());
}
});
request.setRetryPolicy(new DefaultRetryPolicy(
0,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
MySingleton.getmInstance(getActivity()).addToRequestQueue(request);
}catch (Exception e){
Log.d(AppController.DEBUG,"error in the asynctask in the new cases freagment... ");
Log.d(AppController.DEBUG ,e.toString());
}
Log.d(AppController.DEBUG, "Cases size ::" + cases.size());
return true;
}
#Override
protected void onPostExecute(Boolean bool) {
super.onPostExecute(bool);
/* if(listener != null){
listener.getCases(cases);
}*/
adapter.notifyDataSetChanged();
// Log.d(AppController.DEBUG, "new Cases Downloaded...");
}
}
`
(I'm sure that the adapter and recycler view code is correct because I could use the same code now but when I came to test it again it did not work anymore and I can't remember if I changed some thing in it or not - I think not)..
this is my onViewCreate Method .
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.doctor_new_cases_fragment,container,false);
Log.d(AppController.DEBUG_SHARED,"userID in the new case activity ..." + userID);
SharedPreferences prefs = getActivity().getSharedPreferences(AppController.PREFERENCES_NAME , Context.MODE_PRIVATE);
userID = prefs.getString(DoctorProfileSubmitActivity.Shared_userid,null) ;
downloadingNewCases tast = new downloadingNewCases(userID ,"");
tast.execute();
recyclerView = (RecyclerView)view.findViewById(R.id.recyclervew_new_cases);
adapter = new CasesAdapter(view.getContext(), cases);
recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
ViewGroup parent = (ViewGroup) view.getParent();
if (parent != null){
parent.removeView(view);
}
return view;
}
and finally the Array list is declared as an instance variable of the class (the class extends Fragment + it is a fragment that I'm using in my view pager as a tab layout for my tabbed Activity .)
here's the ArrayList declaration
private final ArrayList<Case> cases = new ArrayList<>();
Since you say you can print the data every step of the way, the problem is probably not related to your data. The problem might be your Arraylist of case And your CaseAdapter.
Let's try a simple test, instead of filling your adapter with case objects, create a new ArrayList of string and fill it with object.getString("name") in your on response. Then change your oncreateview to display this list of names using a normal string arrayadapter.
If you can successfully display the names, the it means the bug is in your case and caseadapter, you would have to show more code for us to help.
sorry guys it was not worth it to add a question on the site right away
i fixed the problem . (it appears that my problem was here)
Case ca = new Case(object.getString("ID")
, object.getString("Serial")
, object.getString("Name")
, object.getString("gender")
, object.getString("Age")
, object.getString("NatioanlityID")
, object.getString("HealthProblem")
, object.getString("CityID")
, object.getString("Problem")
, object.getString("Date")
, object.getString("Status")
, spe);
i accidentally changed object.getString("Gender") to object.getString("gender")
which caused me a JSONException .
i fixed that and everything is working again .
thanks for your help and i'm sorry if i rushed to ask the question without a proper debugging session first .
am trying to update my adapter after adding some data in it but its not updating , when i switch through other activities and come back the adapter got updated this time my code :
void updateAdapter(){
adapter.setData(getData());
adapter.notifyDataSetChanged();
Log.d("TAG"," DATA SIZE AFTER UPDATE : "+getData().size() +" items : "+adapter.getItemCount());
}
my adapter :
private void createAdapter(final RecyclerView recyclerView , final List<Information> data) {
List<Information> content = new ArrayList<>();
Log.d("TAG","createAdapter Called");
final int[] currentRowPosition = {0};
content = data;
final List<Information> finalContent = content;
adapter = new ParallaxRecyclerAdapter<Information>(finalContent) {
/// my onBindViewHolder
#Override
public void onBindViewHolderImpl(final RecyclerView.ViewHolder viewHolder, final ParallaxRecyclerAdapter<Information> adapter, final int i) {
currentRowPosition[0] = i;
if ( i <= finalContent.size() -1 ){
((ViewHolder) viewHolder).linearLayout.setVisibility(View.GONE);
final Information current = finalContent.get(i);
((ViewHolder) viewHolder).DESCRIPTION.setText(current.description);
}else {
// this is my loadMore button which stays at the last row of recyclerView
((ViewHolder) viewHolder).setIsRecyclable(false);
((ViewHolder) viewHolder).linearLayout.setVisibility(View.VISIBLE);
((ViewHolder) viewHolder).itemView.getLayoutParams().height = 100;
((ViewHolder) viewHolder).LOADMORE.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
fetchNext();
}
});
}
}
//my on create View Holder
#Override
public RecyclerView.ViewHolder onCreateViewHolderImpl(ViewGroup viewGroup, final ParallaxRecyclerAdapter<Information> adapter, int i) {
return new ViewHolder(getActivity().getLayoutInflater().inflate(R.layout.custom_row, viewGroup, false));
}
#Override
public int getItemCountImpl(ParallaxRecyclerAdapter<Information> adapter) {
return finalContent.size()+1;
}
});
// adding header to recyclerView
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
View header = getActivity().getLayoutInflater().inflate(R.layout.header, recyclerView, false);
headerImageView = (ImageView) header.findViewById(R.id.headerImageView);
//setting CoverImage
adapter.setParallaxHeader(header, recyclerView);
adapter.setData(content);
recyclerView.setAdapter(adapter);
}
any idea how can i add new items with realtime updation on my RecyclerView ?? any guidance will be so helpful for me
I am assuming that when you run the Activity (which has RecyclerView) for the first time it loads everything from the adapter properly.
But when you change to other activities which would change items to your adapter and come back to your Activity which has RecyclerView in it can't get the proper updated information as adapter is not updated.
This may be because you are not refreshing your adapter when your activity resumes in onResume(), something like this. you may have to make other changes to your onResume method as required,
onResume(){
if(adapter != null){
adapter.notifyDataSetChanged();
}
}
Kindly check the lifecycle of an Activity
Example:
This does not directly addresses your issue but help you understand as you come back to activity you should refresh the adapter.
There is a NoteListActivity, with ListView in it, you may Add or edit items to the Adapter in it in NoteEditActivity and as soon as you come back you have to refresh the adapter in the activity where you have your listview
Adapter.class
public void add(List<Information> informations){
try{
finalContent.addAll(informations);
}catch(Exception e){
e.printstacktrace();
}
notifyDataSetChanged();
}
well i ended up with this :
int offset = adapter.getItemCount();
for(int l=0; l<= 4 ; l++){
Log.d("TAG","getData : "+getData().size());
if ((offset - 2) + l < getData().size()){
adapter.addItem(getData().get((offset - 2 ) + l) , adapter.getItemCount() - 2);
adapter.notifyDataSetChanged();
}
}
what i needed was adapter.addItem(item , position) and adapter.notifyDataSetChanged(); the above example is loading 5 images at a time
This application, displays an EEG devices OSC data. So far it can display the it receives from the device.
#Override
public void receiveDataPacket(DataPacket p) {
switch (p.getPacketType()) {
case EEG:
updateEeg(p.getValues());
break;
case ACCELEROMETER:
updateAccelerometer(p.getValues());
break;
case ALPHA_RELATIVE:
updateAlphaRelative(p.getValues());
break;
case BATTERY:
fileWriter.addDataPacket(1, p);
// It's library client responsibility to flush the buffer,
// otherwise you may get memory overflow.
if (fileWriter.getBufferedMessagesSize() > 8096)
fileWriter.flush();
break;
default:
break;
}
}
private void updateEeg(final ArrayList<Double> data) {
Activity activity = activityRef.get();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
TextView tp9 = (TextView) findViewById(R.id.eeg_tp9);
TextView fp1 = (TextView) findViewById(R.id.eeg_fp1);
TextView fp2 = (TextView) findViewById(R.id.eeg_fp2);
TextView tp10 = (TextView) findViewById(R.id.eeg_tp10);
tp9.setText(String.format(
"%6.2f", data.get(Eeg.TP9.ordinal())));
fp1.setText(String.format(
"%6.2f", data.get(Eeg.FP1.ordinal())));
fp2.setText(String.format(
"%6.2f", data.get(Eeg.FP2.ordinal())));
tp10.setText(String.format(
"%6.2f", data.get(Eeg.TP10.ordinal())));
}
});
}
}
I would like to create an array that holds and records the EEG values from the different positions. I would like to populate this list and enable a button that can display a graphical representation of the data.
Could i create an array and populate it as followed in the recieveDataPacket(Datapacket p) case EEG? My problem the data is being updated via a refresh function, which refreshes it and gets the new data. There are 4 positions and i would like to atleast have 5-10 values from each position in an array to populate the line graph.
EEGData[] eegData = new EEGData[]
for(int i = 0; i<eegData.length; i++){
eegData[i] = new EEGData();}
refresh function:
public void onClick(View v) {
Spinner Spinner = (Spinner) findViewById(R.id.spinner);
if (v.getId() == R.id.refresh) {
MuManager.refreshPaired();
List<Device> pairedDevice = MManager.getPaired();
List<String> spinnerItems = new ArrayList<String>();
for (Device m: pairedDevice) {
String dev_id = m.getName() + "-" + m.getMacAddress();
Log.i("Device", dev_id);
spinnerItems.add(dev_id);
}
ArrayAdapter<String> adapterArray = new ArrayAdapter<String> (
this, android.R.layout.simple_spinner_item, spinnerItems);
Spinner.setAdapter(adapterArray);
}
I know that the data is constantly varrying, could i keep a counter for the first 15 values for each position then populate an array which the graph can pull data from.
In my main activity I display a ListView which uses a custom BaseAdapter (ThoughtListAdapter).
listView = (ListView) findViewById(R.id.list);
adapter = new ThoughtListAdapter(this, resultingThoughts);
listView.setAdapter(adapter);
Every item in the ListView has a custom layout containing a TextView and two Button.
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_item_thought, null);
}
thoughtText = (TextView) convertView.findViewById(R.id.thought_text_view);
likeButton = (Button) convertView.findViewById(R.id.thought_like_button);
dislikeButton = (Button) convertView.findViewById(R.id.thought_dislike_button);
When a Button is clicked an AsyncTask (AsyncPost) is called which connects to my database and makes some changes.
likeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
System.out.println("LIKE CLICKED");
Thought t = thoughtItems.get(position);
thoughtId = t.getId();
opinion = 1;
AsyncPost asyncPost = new AsyncPost(activity,ThoughtListAdapter.this);
asyncPost.execute(SHARE_THOUGHT_URL,
TAG_PERSON_EMAIL, "m#b.it",
TAG_THOUGHT_ID, thoughtId.toString(),
TAG_OPINION, opinion.toString());
}
});
What I need is making both Button-s of a list item disappear after the AsyncTask is done with a successful outcome. I have a method onComplete(JSONObject json) which elaborates the JSONObject returned by the AsyncTask. I try to make the buttons non visible inside the onComplete method, but this doesn't work because onComplete() doesn't know which exact button has been clicked.
How can I pass an instance of the exact clicked button inside onComplete() and make disappear only the Like and Dislike buttons of the concerned list item?
AsyncPost is a global AsyncTask used by all my other activities. I would strongly prefer to leave it alone. The onComplete() method functions as the onPostExecute() method of the AsyncTask.
Here are the getView() and onComplete() methods inside my BaseAdapter, which contain all the code shown above.
Thank you.
public View getView(final int position, View convertView, ViewGroup parent) {
if (layoutInflater == null) {
layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.list_item_thought, null);
}
thoughtText = (TextView) convertView.findViewById(R.id.thought_text_view);
likeButton = (Button) convertView.findViewById(R.id.thought_like_button);
dislikeButton = (Button) convertView.findViewById(R.id.thought_dislike_button);
//thoughtItems is a list of custom ojbects (Thought)
Thought t = thoughtItems.get(position);
//Here i set the content of the current TextView
thoughtText.setText(t.getText());
//the two buttons do basically the same thing when get clicked
likeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Thought t = thoughtItems.get(position);
thoughtId = t.getId();
opinion = 1;
AsyncPost asyncPost = new AsyncPost(activity,ThoughtListAdapter.this);
asyncPost.execute(SHARE_THOUGHT_URL,
TAG_PERSON_EMAIL, "m#b.it",
TAG_THOUGHT_ID, thoughtId.toString(),
TAG_OPINION, opinion.toString());
}
});
dislikeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Thought t = thoughtItems.get(position);
thoughtId = t.getId();
opinion = 0;
AsyncPost asyncPost = new AsyncPost(activity,ThoughtListAdapter.this);
asyncPost.execute(SHARE_THOUGHT_URL,
TAG_PERSON_EMAIL, "m#b.it",
TAG_THOUGHT_ID, thoughtId.toString(),
TAG_OPINION, opinion.toString());
}
});
return convertView;
}
#Override
public void onComplete(JSONObject json) {
if (json != null) {
try {
if (json.getInt(TAG_SUCCESS) == 0) {
Toast.makeText(activity, "Operazione non riuscita.", Toast.LENGTH_LONG).show();
} else {
//if everything is good i try to make the buttons of that particular list item disappear
likeButton.setVisibility(View.GONE);
dislikeButton.setVisibility(View.GONE);
}
}
catch (JSONException e) {
Log.e(TAG_LOG, "JSONException", e);
}
}
else Toast.makeText(activity, "Errore connessione!", Toast.LENGTH_LONG).show();
}
One solution to this would be to have something on your Thought object to indicate whether or not to show the buttons.
So in your getView() method you check this
likeButton = (Button) convertView.findViewById(R.id.thought_like_button);
dislikeButton = (Button) convertView.findViewById(R.id.thought_dislike_button);
Thought t = thoughtItems.get(position);
if (t.hideButtons()) {
likeButton.setVisibility(View.GONE);
dislikeButton.setVisibility(View.GONE);
}
else {
likeButton.setVisibility(View.VISIBLE);
dislikeButton.setVisibility(View.VISIBLE);
}
Then you would need to have your onComplete method return the id of the Thought object that it related to. Then inside your onComplete you could do
int id = //get your id from your JSON response
for(Thought t : thoughtItems) {
if (t.getId() == id) {
t.setHideButtons(true);
notifyDataSetChanged();
break;
}
}
By calling notifyDataSetChanged() it will redraw your list and when it does the check for whether it should show the buttons or not it will not show them because it was set on that thought item