0

I got a asynctask listview that displays name, email, phonenumber. I update the name of the selected item on a dialog box but it shows it as an array. How can make it show a specific value for example "Name"?

Default: Name: name1, email:[email protected], mobile:000 When I open dialog box textview will show {email=email,name=name,id=c201,mobile=000}

I want this to show just 'name' on the textview

ListView lv = getListView();

// Listview on item click listener
lv.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> parent, final View view, final int position, long id) {

        // getting values from selected ListItem
        final String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
        String cost = ((TextView) view.findViewById(R.id.email)).getText().toString();
        String description = ((TextView) view.findViewById(R.id.mobile)).getText().toString();

        // Create custom dialog object
        final Dialog dialog = new Dialog(MainActivity.this);
        // Include dialog.xml file
        dialog.setContentView(R.layout.custom);
        // Set dialog title
        dialog.setTitle("Custom Dialog");

        // set values for custom dialog components - text, image and button
        final TextView text = (TextView) dialog.findViewById(R.id.name_label);
        text.setTextColor(Color.GREEN);
        dialog.show();

        new CountDownTimer(30000, 1000) {

            public void onTick(long millisUntilFinished) {

                String itemValue =  (lv.getItemAtPosition(position).toString());
                text.setText(itemValue);
            }

            public void onFinish() {

            }
        }.start();
   }

2 Answers 2

2

Your listview must have been bound a adapter,and your text on textview comes from an array,so you should get the every string from your array data,not from listview directly.

Replace :

String itemValue =  (lv.getItemAtPosition(position).toString());

with:

String itemValue =  (YourArray[position].toString());//YourArray is your data array for showing text on textview
Sign up to request clarification or add additional context in comments.

Comments

1

To get data from Listview You can get data directly from your List of data (ArrayList, String[], JsonArray whatever you have used) using the position what you got from onItemClick

eg. Arraylist listArrayObj.get(position)
JsonArray listJsonarrayArrayObj.get(position)
String[] than yourStrArra[position]

Suggestion


DON'T

final String name = ((TextView) view.findViewById(R.id.name)).getText().toString();
                String cost = ((TextView) view.findViewById(R.id.email))
                        .getText().toString();
                String description = ((TextView) view.findViewById(R.id.mobile))
                        .getText().toString();

DO

fetch value of array directly from the Array which is passing in adapter

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.