0

I have a listview with two buttons.

I want replace those two button with textview once I get the response from the server.

How can I achieve this?

After server response:

public void onResponse(String response) {
                    try {
                        JSONObject obj = new JSONObject(response);

                        if (obj.getString("response").equals("1")) {
                            JSONObject res = new JSONObject(obj.getString("data"));

                            Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }

I have not created any adapter.

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
  • ok, first in your layout create theses two buttons and set visibility = visible and create textview and set it's visibility = gone , and when your response come you can set visibility for the buttons to be( gone) and for the textview to be (visible) – Mosa Jan 07 '18 at 08:26
  • how to get which row button got clicked after server response and same row textview should show and hide that clicked button – Yana Shetty Jan 07 '18 at 10:02
  • then your request that buttons and textview inside listview ?? you don't say that in your question , your question not obvious !! then what your question exactly ?? you want when click on button inside listview to make theses action ? – Mosa Jan 07 '18 at 10:11
  • okay..let me tell you what i want is.. there is timer, once click lap button it will keep on generate like. 1. 00:00;45 scanButton 2. 00:00;45 scanButton etc. once I press the scan button am sending scan details to server and response will be fulname.. then I want to show that name in that particular row and hide that scan button..thats it. – Yana Shetty Jan 07 '18 at 10:18
  • ok i will write my answer in the answers wait – Mosa Jan 07 '18 at 10:23
  • okay..or else I am ready to send you the code. Can you fix it for me please – Yana Shetty Jan 07 '18 at 10:28
  • sorry i am busy right now , see my answer ,, and really stop using listview and start using recyclerview – Mosa Jan 07 '18 at 10:39

2 Answers2

0

you need to extend ArrayAdapter for customizing your listview items.

On your xml, keep both button and text views and for the textview, keep

android:visibility="gone"

initialize both textview and button in your adapter class. when you get the response, enable textview visibility and disable button visibility

textView.setVisilibity(View.VISIBLE);
button.setVisilibity(View.GONE);
Sabid Habib
  • 419
  • 1
  • 4
  • 16
0

ok i understand your problem and the best way is using recyclerview instead of listview , first of all see this example or recyclerview recyclerview example this is simple and best than normal listview , second in onBindViewHolder function you can create your own listner like this

 @Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.your_sender_button.setonclickLinstener(new View.OnClickListener { @Override
    public void onClick(View view) {
      yourActivity.sendTimer(holder.btn1, your_sender_button, holder.your_textview_name);
    }
});
}

sendTimer is the function used service to send the timer and the parameters is your views, so when you get the response set the visibility for these views you passed in your function

Mosa
  • 353
  • 2
  • 16
  • if you want to send your code send it , but maybe tomorrow i will re-send it to you , because i am working right now – Mosa Jan 07 '18 at 10:56
  • ok no problem!! I ll try with recyclerview once.. how can I send the code?? – Yana Shetty Jan 07 '18 at 10:58
  • if you have dropbox or github you can set your code in them , it's very simple .. – Mosa Jan 07 '18 at 11:12
  • see this tutorial as will ,, https://www.android-examples.com/android-simple-recyclerview-example-tutorial/ . this is simple example for using recylerview – Mosa Jan 07 '18 at 11:13
  • I can setup a recyclerview but how can I hide particular row button and show particular row textview. after scan? how to get the row position in onActivityResult() – Yana Shetty Jan 07 '18 at 11:20
  • how to use onActivityResult() in adapter to get results of scanner?? – Yana Shetty Jan 13 '18 at 13:00
  • you can't use onActivityResult in adapter, it used just in activity or fragment just – Mosa Jan 14 '18 at 05:36